Tuesday, 16 June 2015

Dropdown in Rails

Making Dropdown in rails is really simple. All we need to do is make a list of items to be displayed in the dropdown and select them all in the form with ease.
First of all, make a constant variable in the corresponding .rb file, say example.rb which has the following content.


class Example < ActiveRecord::Base 
 CLASS_LIST = ["Nursery", "KG1", "KG2"]
end

Now in the form write the following piece of code to show the dropdown


<div class="field">
    <%= f.label :class_name %><br>
    <%= f.select(:class_name, Example::CLASS_LIST) %>
  </div>

Remember, here the Example is the class name and CLASS_LIST is the constant variable name. Now run the project and you will see the dropdown with the list of items mentioned in the constant variable.

You can also watch the video

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel