rails nested model forms has_one association -


im using simple_form gem , need nested form im having trouble here code:

i have 2 models:

apiphones:

class apiphone < activerecord::base   attr_accessible :key, :phone   validates_presence_of :phone   belongs_to :store end 

stores:

class store < activerecord::base   has_one :apiphone   accepts_nested_attributes_for :apiphone end 

and in view:

<%= simple_form_for [@group,@store] |f| %>     <%= f.simple_fields_for :apiphone |ph| %>       <%= ph.input :phone %>     <% end %> <% end %> 

but nothing showing, ideas?

using fields_for in conjunction accepts_nested_attributes assumes records initialized. means that, using models, @store.apiphone should not nil when form generated. way solve issue making sure apiphone initialized , associated @store (both new , edit actions).

def new   @store = store.new   @store.build_apiphone end 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -