Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Rails:Populating Select boxes with model data

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 72
    Comment on it

    In model specific form we use select method to display a select box and populate it with model data.


    @location =
    <%= select(:location,:city_id,City.all.collect {|p| [, ] }) %>
    <%=,City.all.collect {|p| [, ] }) %>
    where f is the form object.

    select tag also takes optional arguments . They are :

    :multiple - When set to true we can select more than one option.

    :disabled - When set to true the select box will be disabled in the web page

    :include_blank - When set to true an empty option will be created

    :prompt - When a string is passed to this option it is displayed as option without any value in the web page.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: