RoR - Select Box Using Existing Model


/ Published in: Rails
Save to your folder(s)

The code to find all objects from a model and use them as select options.


Copy this code and paste it in your HTML
  1. # Replace |model| with whatever you want to use. ie. |whatever|
  2. <%= select(:object, :name, Model.all.collect {|model| [model.name, model.id]}) %>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.