Posted on November 23rd, 2015 by Bachan Smruty
Most of the developers have been working in rails 3.0.1, but the new version of rails (i.e. 3.1) is available now. I am going to discuss all the new features that I have found in rails 3.1 till now. 1. Auto bundle install In rails 3.0.1, after creating the new application, we need to make […]
Posted on November 23rd, 2015 by Sabyasachi Ghosh
This a tip on real time ajax pushing using faye and private pub in rails 3 Gems used: gem “private_pub” gem ‘thin’ gem ‘faye’ Step 1 : generate a new rails app using rails new App_name Step 2: install the above the mentioned gem in your gem file and run the bundle […]
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| […]
Posted on November 23rd, 2015 by AJAY SAHU
Let’s say we are adding a basic signing functionality to our application and we want the current_user(which is under User Controller) should be available for other Model file. We have a model called Comment and we wish to make current_user accessible here. Inside app/views/controller/ApplicationController.rb define a method which assigns current_user to a cattr_accessible attribute defined […]
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 […]
Posted on November 23rd, 2015 by AJAY SAHU
What ? In this tip I am going to demonstrate how to create your first basic Rails application without writing a single line of Ruby code. How ? Rails has a beautiful concept called scaffolding,using which a novice programmer can also create his first Rails App. Just follow 5 basic steps and get your first […]
Posted on November 23rd, 2015 by AJAY SAHU
Scenario: Let’s say we are having 10 migration files in our application. Our DB is already set as per our migrations. Now let’s say we got a requirement to add a new column to an existing table. Literally we need to update our migration file and synchronize the same with database. Description: We are having […]
Posted on November 23rd, 2015 by Ajay Sahu
Generally on starting the server, it takes port 3000. If you want to change port then we can specify port number manually by appending our rails s with -p port_no. But we can change our default port no by adding few lines of codes. With Following Command our Rails Server starts at Default port 3000 […]
Posted on November 23rd, 2015 by AJAY SAHU
What exactly filter is ? Filter is a simple method which is executed “before” / “after” / “around” a controller action. For example, one filter might check if the user has the credentials for accessing a particular action in a controller. Where can I place my filter ? Filters are inherited so if you a […]
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 […]
Posted on November 23rd, 2015 by Ajay Sahu
Rails ships with nice collection of model validations. By default rails facilitizes our application with validations like presence, uniquiness, format etc etc. In most applications default supplied validations are enough to serve our purpose. But in few cases we are required to add few custom validations to our rails applications. Problem statement : Let’s assume, […]
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 […]
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 […]
Posted on November 23rd, 2015 by AJAY SAHU
In data-drive development environment we need couple of pre-existing data in our application. Literally in your rails application if we wish to deploy few dummy / starting data then we can use seed and execute it in deployment script (everytime when a new app is installed). -We will place our dummy records in our db/seeds.rb […]
Posted on November 23rd, 2015 by AJAY SAHU
Let’s take a scenario. We have already uploaded our rails project to github. Now we want to perform few changes and update the same to our Github repository. Go through following steps to get access to your git repository & upload the project (with new changes) back to Github. Open CMD/Terminal window : # clone […]
Posted on November 23rd, 2015 by AJAY SAHU
Mass Attribute updates are a good time saving feature in rails. But in case if we want to protect your model attributes and we don’t want users to be able to update it directly ???? In Such case rails Active Record provides two built-in ways to protect attributes from mass-assignment. We have two options here […]
Posted on November 23rd, 2015 by Ajay Sahu
In following tip we’ll walk down with few steps to upload your rails Project to Github. Create your free github account @ Github Configuration in Github account : Create a new repository in your Github account: repository_name Enter your repository name: give_any_name Provide a short description regarding your project (optional) & and choose public type […]
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 […]
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 […]
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 […]