“as_json” Rails

as_json has very flexible way to configure complex object according to model relations

EXAMPLE

Model campaign belongs to shop and has one list
Model list has many list_tasks and each of list_tasks has many comments
We can get one json which combines all those data easily.

@campaign.as_json(
    {
        except: [:created_at, :updated_at],
        include: {
            shop: {
                except: [:created_at, :updated_at, :customer_id],
                include: {customer: {except: [:created_at, :updated_at]}}},
            list: {
                except: [:created_at, :updated_at, :observation_id],
                include: {
                    list_tasks: {
                        except: [:created_at, :updated_at],
                        include: {comments: {except: [:created_at, :updated_at]}}
                    }
                }
            },
        },
        methods: :tags
    })

Notice methods: :tags can help you attach any additional object which doesn’t have relations with others. You just need to define a method with name tags in model campaign. This method should return whatever you need (e.g. Tags.all)

Official documentation for as_json

Advertisements

RVM – Gemsets

Creating gemsets

Gemsets must be created before being used. To create a new gemset for the current ruby, do this:
rvm 2.1.1
rvm gemset create teddy
Gemset 'teddy' created.

Alternatively, if you prefer the shorthand syntax offered by rvm use, employ the –create option like so:
rvm use 2.1.1@teddy --create

Select gemsets according to the Project

There is a new way to do this, without having to allow arbitrary shell script to be executed in a .rvmrc file.

Create a file named .ruby-gemset containing only the gemset name in.
multilingo_cms
Need an up to date version of rvm for this to work.

You can also specify the ruby version by creating a file named .ruby-version containing only the ruby version:
1.9.3


This format also has the advantage of being compatible with rbenv and rbfu.

If you have existing projects using the deprecated .rvmrc, you can convert them to the new format using the command:
rvm rvmrc to .ruby-version

RubyMine Ubuntu

rubymine-ide-banner

Install RubyMine

  1. Download RubyMine from Source
  2. Unpack the downloaded archive:
    1. tar -xzf RubyMine-X.Y.Z.tar.gz
  3. Goto extracted folder, nevigate to ‘bin’ directory
    1. ./rubymine.sh
  4. Open any project, goto (Tools) -> (Create Desktop Entry)

Change Rubymine Theme

  1. File -> Settings -> Appearance and Behavior -> Appearance

Remove RubyMine

  1. locate rubymine
  2. locate RubyMine
  3. rm -rf ~/.RubyMine

 

Install Sublime Text 3 Ubuntu

logo_sublimetext_lachicainf

You have to add the PPA to your system, update the local repository index and install the sublime-text-installer:

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

Optional, to remove sublime text, do:
sudo apt-get remove sublime-text-installer

Registration License Key:

—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04
B085E65E 2F5F5360 8489D422 FB8FC1AA
93F6323C FD7F7544 3F39C318 D95E6480
FCCC7561 8A4A1741 68FA4223 ADCEDE07
200C25BE DBBC4855 C4CFB774 C5EC138C
0FEC1CEF D9DCECEC D3A5DAD1 01316C36
—— END LICENSE ——

 

Sublime Text 3 Serial key build is 3143

—– BEGIN LICENSE —–
TwitterInc
200 User License
EA7E-890007
1D77F72E 390CDD93 4DCBA022 FAF60790
61AA12C0 A37081C5 D0316412 4584D136
94D7F7D4 95BC8C1C 527DA828 560BB037
D1EDDD8C AE7B379F 50C9D69D B35179EF
2FE898C4 8E4277A8 555CE714 E1FB0E43
D5D52613 C3D12E98 BC49967F 7652EED2
9D2D2E61 67610860 6D338B72 5CF95C69
E36B85CC 84991F19 7575D828 470A92AB
—— END LICENSE ——

Setup Ubuntu Machine

banner-772x250

Install Packages

sudo apt-get install -y curl
sudo apt-get install -y build-essential
sudo apt-get install -y bison byacc gperf
sudo apt-get install -y zlib1g-dev
sudo apt-get install -y libreadline5
sudo apt-get install -y libreadline-dev
sudo apt-get install -y libncurses5 libncurses5-dev
sudo apt-get install -y libssl-dev
sudo apt-get install -y autoconf
sudo apt-get install -y libxml2
sudo apt-get install -y libxml2-dev
sudo apt-get install -y libpng12-0
sudo apt-get install -y libpng12-dev
sudo apt-get install -y libgmp3-dev
sudo apt-get install -y sendmail
sudo apt-get install -y libjpeg62-dev
sudo apt-get install -y openssh-server
sudo apt-get install -y gettext
sudo apt-get install -y imagemagick
sudo apt-get install -y graphicsmagick-libmagick-dev-compat

Install and configure GIT

sudo apt-get install git-core

Colored Git
git config –global color.diff auto
git config –global color.status auto
git config –global color.branch auto
git config –global color.interactive auto
git config –global color.ui true
git config –global push.default tracking
git config –global core.autocrlf false
git config –global core.safecrlf false
git config –global core.ignorecase false
git config –global core.excludefile ~/.gitignore
git config –global diff.renames copies

Install and configure Mysql

sudo apt-get install libmysql++-dev
sudo apt-get install -y mysql-server

Install and configure PHP

sudo apt-get install php

Install PHPMyAdmin

sudo apt-get install phpmyadmin

Install Ruby and Gems

sudo apt-get install ruby
sudo apt install ruby-railties

Install Rvm

curl -L https://get.rvm.io | bash -s stable