Collection_select not working for nested forms

hi guys,

Ruby 1.8.7
Rails 2.3.5

I have a nested form in which a select drop down works fine for
the model, but on edit form it does not show the current value.
It gets set to the default option.

The domain is like this:
Listing <has_one> Address <belongs_to> Neighbourhood

The drop down used to work for address edit form, before nesting the

address.rb ->
partial _address_form.html.erb ->

The method @neighbourhood_for_metro in following snippet is a helper
works perfectly fine.

<%= address_form.label :neighbourhood %>
<%= collection_select(:address,:neighbourood,@neighbourhood_for_metro,:id,:name) %>

I spent enough time on this issue to know its some silly thing that
I am missing.

I would really appreciate if any one could help me solve this issue.


Try changing the method to :neighbourhood_id

I have tried that, no change in behaviour.

worked rather than collection_select(@object,@method,…)

it seems use of form specific methods avoids a lot of trouble, when
forms from individual to nested.


Spotted a little typo in on line 15: <

That :neighbourood missing h.

Maybe theres your problem?

Any difference if you change :address to @address?

If that doesnt work, I guess you’ll have to do :selected =>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs