Posts

Showing posts with the label ruby

Insert Bulk data using active record import

Imagine a scenario where you have to create a report and send it to multiple clients, so lets just say you have a report model and you have client and you have report client model. lets first check all the association and model structure. #report model class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients end #report_client class ReportClient < ActiveRecord::Base   belongs_to :report   belongs_to :client end #clients class Client < ActiveRecord::Base   has_many :report_clients   has_many :reports, through: :report_clients end No lets say you want to create a report for 30 clients. You can do that by adding nested attributes in rails. so our report model will became  class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients   accepts_nested_attributes_for :report_clients, :reject_if => proc { |attributes| att

Insert Bulk data using active record import

Imagine a scenario where you have to create a report and send it to multiple clients, so lets just say you have a report model and you have client and you have report client model. lets first check all the association and model structure. #report model class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients end #report_client class ReportClient < ActiveRecord::Base   belongs_to :report   belongs_to :client end #clients class Client < ActiveRecord::Base   has_many :report_clients   has_many :reports, through: :report_clients end No lets say you want to create a report for 30 clients. You can do that by adding nested attributes in rails. so our report model will became  class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients   accepts_nested_attributes_for :report_clients, :reject_if => proc { |attributes| att

Install Ruby on Rails on Mac

Please follow the below steps to i nstall RVM RUBY RAILS and Postgres in MAC yosemite. Step 1. Install Homebrew Homebrew is a package manager for the Mac. Installing Homebrew by issuing the following command: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) " To make sure Homebrew is installed correctly run: brew doctor Step 2: Install GPG Package. Download and install the GPG package from the link https://gpgtools.org Step 3: Install RVM gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 and \curl -sSL https://get.rvm.io | bash -s stable Reload your bash_profile, so it can initialize RVM. ~/.bashrc Run RVM requirements to install basic required packages with Homebrew. Accept the license agreement and install Xcode Tools. After installing the tools continue the rvm requirements installation. rvm requirements Step 4. Install Requir

Set up Neo 4j With Rails In Ubuntu

How to setup new 4j database with Rails 4. Step 1: Install Neo4j Database in ubuntu.   login as Admin  sudo -i  wget -O - http://debian.neo4j.org/neotechnology.gpg.key | apt-key add -  Add Neo4J to the Apt sources list:   echo 'deb http://debian.neo4j.org/repo stable/' > /etc/apt/sources.list.d/neo4j.list  Update the package manager:  exit as admin  apt-get update  Install Neo4J:  apt-get install neo4j  sudo /etc/init.d/neo4j-service restart Step 2: Create a new rails project.  Rails new neo4j Step 3:  Add neo4j Gem in your gem file   gem 'neo4j', github: 'andreasronge/neo4j' Step 4: Go to application.rb require File.expand_path('../boot', __FILE__) require "rails" %w(   neo4j   action_controller   action_mailer   sprockets ).each do |framework|   begin     require "#{framework}/railtie"   rescue LoadError   end end # Require the gems listed in Gemfile, including any gems # you've

Creating RESTful API using Grape and RABL in Rails 4

We can create a RESTful API using Grape and RABL in Rails4. Step 1: Add this GEMS in your Gem file, And do Bundle install.  gem 'grape'  gem 'rabl-rails'  gem 'grape-rabl'  gem 'rack-cors', :require => 'rack/cors' Step 2: Create a file under lib directory called api.rb, and create a folder inside the view named as api. # lib/api/v1/root.rb class API < Grape::API end Step 3: Add this line to your application.rb file    config.paths.add "app/api", glob: "**/*.rb"     config.autoload_paths += %W(#{config.root}/lib #{config.root}/app/api/*)     config.middleware.use Rack::Cors do       allow do         origins '*'         # location of your API         resource '/*', :headers => :any, :methods => [:get, :post, :options, :put, :delete]       end     end     config.middleware.use(Rack::Config) do |env|       env['api.tilt.root'] = Rails.root.join "app", "

Set up Jruby with apache and passenger in EC2

How to set up jruby with apache and passenger in amazone ec2. Step 1: First install jruby using please check the current version in the   link . And make sure you are installing the bin version of it wget 'http://jruby.org.s3.amazonaws.com/downloads/1.7.4/jruby-bin-1.7.4.tar.gz' Step 2: extract the tar file using tar zxvf jruby-bin-1.7.4.tar.gz Step 3: We need to set come environment variable so that it will be accessible from every other place. export JRUBY_HOME=/home/home_directory_name/jruby-1.7.4 export PATH=$JRUBY_HOME/bin:$PATH And Open the .bashrc file and put the path in their sudo nano ~/.bashrc PATH=$PATH:/home/ubuntu/jruby-1.7.4/bin Step 4: Now to check if jruby is properly installed or not put jruby-v If your system does not have java installed then it will show an error like /home/ubuntu/jruby-1.7.4/bin/jruby: line 395: exec: java: not found Don't worry we will install java to fix this. sudo apt-get install openjdk-7-jdk apt-cache

Set up ruby 2.0 and Rails 4.0.1 in Rackspace

First we need to install ruby Step 1)Install Ruby apt-get -y update apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev cd /tmp wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz tar -xvzf ruby-2.0.0-p247.tar.gz cd ruby-2.0.0-p247/ ./configure --prefix=/usr/local make make install Step 2) Install Rails gem install rails 4.0.1 Step 3) Install passenger gem install passenger Step 4) Install Apache2 apt-get install apache2 Step 5) Install Mysql sudo apt-get install mysql-server mysql-client That's it we are done with the setup.