5

I created 2 models using scaffolding with Rails 3. The models are Locations and Jobs and each job has a location.

I created the required reference calls in the scaffold generation code but when I look at the view to create a new job, all I see is a textbox where I should add the location_id.

How can I get that to be a dropdown instead for a better user experience?

Pan Thomakos
  • 34,082
  • 9
  • 88
  • 85
femi
  • 974
  • 2
  • 13
  • 44
  • A duplicate of [Rails: Scaffold to automatically do one-to-many relationship](http://stackoverflow.com/questions/502119/rails-scaffold-to-automatically-do-one-to-many-relationship) The behavior that you want will come from a third party. – givanse Dec 08 '13 at 17:34

1 Answers1

16

Imagine, that you have got title for each location

<%= f.collection_select :location_id, Location.all, :id, :title %>

API: http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/collection_select

fl00r
  • 82,987
  • 33
  • 217
  • 237