Posts

Showing posts from January, 2015

Create Nested form In Ruby on Rails 4.1

In Rails we create simple form and also sometimes we need nested form. In Rails we can easily do that using  gem “nested_form”. let's create a project using “nested_form”. Before that I would like to ask you to have a look on nested_attribute_documentation(http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#method-i-accepts_nested_attributes_for). 1) Create a new Rails 4 Project.     rails new nested_app 2) Include the gem in your gem file.   gem "nested_form" 3) run bundle install  bundle install 4) Generate the necessary javascript file.   rails g nested_form:install 5) Include the javascript file in the asset pipeline. in the application.js add the below line.   //= require jquery_nested_form 6) Let say we have a Exam model and one Exam can have multiple Questions.So lets create the Exam model. class Exam < ActiveRecord::Base   has_many :questions, dependent: :destroy   accepts_nested_attributes_for :questions,