Reputation: 367
I have a controller called user with the action new. This action has a view associated called new.html.erb
def new
@break_point = BreakPoint.new
@provinces=Province.all
respond_to do |format|
format.html # new.html.erb
format.json { render json: @break_point }
end
end
The problem is I want to create a select field in ROR for fill this with the array of provinces @provinces
Example <% @provinces.each do |province| %>
<% f.select ? %>
<% end %>
Upvotes: 0
Views: 215
Reputation: 52357
Despite the fact, that I have no idea what this line @provinces=provinces.all
does (I assume, you've meant Province.all
, but that's just a suggestion), the select would look as follows:
<%= f.select :province, collection: provinces.map(&:name) %> #where `name` is an attribute of Province model, and you can substitute it with whatever attribute you want user to be able to select by.
Upvotes: 2