We have a user model which :has_one detail. In a form_for a user, I want a drop-down to select the user’s details’ time_zone.
I’ve tried
<% form_for @user do |f| %>
... user stuff ...
<%= f.select :"detail.time_zone", ...other args... %>
<% end %>
but I get a NoMethodError for detail.time_zone. What’s the correct syntax for doing this – or if it’s not possible to do it this way, how should I be doing it?
Don’t forget to use
accepts_nested_attributes_forin your user model:Detail model:
Users controller:
User new/edit view: