Notes on ScopePort

Tag: standard

How to add a value to a select field in Ruby On Rails

by Lennart on Nov.15, 2008, under Ruby On Rails

I’ll just leave this here: When you fill a select box directly from a array returned by .find(:all) you can add more values tothe select box this way:

Controller:

    @hosts = Host.find(:all).collect {|p| [p.name, p.id] }
    @hosts << ["None", nil]

View:

    <dd>
      <%= f.select :linkedhost, @hosts %>
      <%= error_message_on(:service, :linkedhost) %>
    </dd>
Leave a Comment :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!