ruby on rails - one view two controllers -


my app got installation controller , address controller.

address has_one :installation , installation belongs_to :address 

in installation view, got simple_form inside in other simple_form. this:

<%= simple_form_for @installation, class: 'form-horizontal' |f| %>     <%= f.error_notification %>          <%= f.simple_fields_for @installation.address |u| %>               <%= u.label :street_address, label: t('address.address_label'), required: true, class: 'col-sm-2 control-label' %>                 <%= u.input_field :street_address, class: 'form-control'                 %> 

so how can update 2 models ?

can have 2 def params ? likes this:

def installation_params     params.require(:installation).permit(x) end  def installation_address_params     params.require(:????).permit(y) end 

you can use nested attributes.

untested, roughly:

model:

class installation < activerecord::base   belongs_to :address    accepts_nested_attributes_for :address end 

and in installationscontroller:

params.require(:installation).permit(...,   address_attributes: [:id, ...]) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -