" Live as if you were to die tomorrow. Learn as if you were to live forever.. "
- Mahatma Gandhi

Integrating Simple_Form Gem To Rails Application

Posted on November 23rd, 2015 by Ajay Sahu

Why we have chosen simple_form : – simple_form is lightweight – It comes up with basic HTML mark up giving freedom to customize the CSS at your own comfort. Build a basic application: $ rails new DemoApp $ rails g scaffold blog title:string description:text $ rake db:migrate Now check app/blogs/_form.html.erb : <%= form_for(@blog) do |f| […]

Add Pagination in Rails

Posted on November 23rd, 2015 by Ajay Sahu

This tip shows how to add pagination in Rails. Let’s create a basic rails project : $rails new pagination #creating project $cd pagination $rails generate scaffold user name:string address:string #Createed a basic app with 2 fields name & Address $rake db:migrate #let’s create our users table in Database. Now run your rails server & Navigate […]

Send SMS from fullonsms.com via our Rails Application

Posted on November 23rd, 2015 by AJAY SAHU

By using  this small Trick we can send SMS to any Indian Mobile number from fullonsms via our Rails Application. For this we need  a gem ‘mechanize’  It will help us to render our html pages, forms, form elements etc . So let’s go ahead and install this gem for our Rails application. Add gem […]

Render Prev & Next Record From Show Page in Rails

Posted on November 23rd, 2015 by AJAY SAHU

Scenario: In Rails we can click individual record and open it from index page but to open the next record we need to go back to index & click another link.  But we can have a Prev / Next Navigation options in our show page to render our previous/next records without clicking individual links. We […]

Clear Cache in Rails

Posted on November 23rd, 2015 by AJAY SAHU

On implementing basic sign in functionality we need to handle our session properly. Even after proper session management, in following case we can view users confidential profile information. ->login into app ->Move to profile page -> Tap on Logout ->Press back button of browser -> Getting my last visited page(profile Page) We need to clear […]

Speed up your Webrick Server

Posted on November 23rd, 2015 by Ajay Sahu

In development environment when you try to access your application via other system, app behaves quite slow. With a small configuration with our server we can make it faster. Speed up your Webrick Server : Locate your config.rb File: For Linux User: /usr/lib/ruby/1.9.1/webrick/config.rb For Windows User: C:\RailsInstaller\Ruby1.9.3\lib\ruby\1.9.1\webrick\config.rb Replace following line: :DoNotReverseLookup => nil, with :DoNotReverseLookup […]

Integrate Simple_form Gem To Rails Application

Posted on November 23rd, 2015 by AJAY SAHU

We got many gems to customize our form in rails out of which we will be using simple_form. Why we have chosen simple_form : – simple_form is lightweight.   – It comes up with basic HTML mark up giving freedom to customize the CSS at your own comfort. Build a basic application: $ rails new DemoApp […]

Detect & Customize Installed Gem Versions in Rails

Posted on November 23rd, 2015 by AJAY SAHU

Here we’ll see 3 basic rails commands to Identify which version of gems we are using. In many instances our application does not support couple of gem version. in that case we need to detect what’s the exact version, then need to remove the unsupported version to make our app run cleanly. Run below commands […]

Change Your Default Root Path In Rails

Posted on November 23rd, 2015 by AJAY SAHU

On running a freshly created app, we get default rails page( printed below, which signifies our server is running perfectly alright). But actually this page is none of our use. We can simply replace this page with any page as per our need. Create a project first: $ rails new DemoApp $ rails g scaffold […]

Using UJS in will_paginate gem in Rails3

Posted on November 23rd, 2015 by Bachan Smruty

The will_paginate (https://github.com/mislav/will_paginate) gem is a popular gem, that developers usually use for the pagination. It populates the links for the pagination and upon clicking the link, it will load the content. For adding UJS to these paginate links, we need to override the helper methods of the will_paginate gem. In the following, I am […]

Skinny C & Fat M approach in Rails

Posted on November 23rd, 2015 by Ajay Sahu

Basically whe we are novice to rails application, we used to place all our codes in our view pages and used to keep our model & controller files almost blank. For a sample app  our view, controller and model files used to look some way similar to this : #view               Here we […]

Use of ‘prawn’ gem to generate PDF in Rails

Posted on November 23rd, 2015 by Shatabdi Mohapatra

Add this gem to the gemfile of your application and run the ‘bundle’ command. gem ‘prawn’ Create a PDF Mime::Type inside config/initializers/mime_types.rb. Mime::Type.register “application/pdf”, :pdf   I have created a respond block with HTML and PDF format inside my controller. Inside the format.pdf block, the send_data method is called. respond_to do |format| format.html format.pdf do […]

Downloading Attachments From Mails Through IMAP in Rails

Posted on November 23rd, 2015 by Shatabdi Mohapatra

Sometimes there is a requirement to download the attachments of mails being accessed thorugh IMAP protocol in Rails. 1. Firstly, we need to connect to imap and login to the mail account of the user. def get_messages require ‘net/imap’ require ‘mail’ imap = Net::IMAP.new(params[:host], params[:port], params[:ssl]) imap.login(params[:username], params[:password]) 2. Then we need to select the […]

Using Mongo_mapper for MongoDB

Posted on November 23rd, 2015 by Anuj Dubey

According to mongodb.org, in rails there are two leading gems Mongo_mapper and mongoid to use mongodb as database . Here we will see mongo mapper with rails. In rails Mongomapper is an easy way to model our application and persist our data in MongoDB. To install MongoMapper gem gem install mongo_mapper class Employee include MongoMapper::Document […]

Use MySQL DB for your rails Application ( Windows)

Posted on November 23rd, 2015 by Ajay Sahu

Here I am assuming ruby on rails setup + MySQL Database has been installed in your windows machine. We will follow couple of steps and will use MySQL Database for our rails application. Step -1: $ rails new mySQL_Example –database=mysql #by applying –database=mysql parameter, check your Gemfile, it must include gem ‘mysql2’. our procedure seems […]