Form for 2 models?

Is it possible to have a form_for :model_1, :model_2 ?

Thanks

Ok, I figured out how to do it, but now I’m having soe trouble.

I want to be able to add model_2’s to model_1, when model_1 already
exists

def save_model_1
current_model_1 = Model_1.find(params[:model_1])

if current_model_1
  @model_2 = current_model_1.model_2s.build(params[:model_2])
else
  @model_1 = Model_1.new(params[:model_1])
  @model_2 = current_model_1.model_2s.build(params[:model_2])
end

if current_model_1
    render :action => 'index'
else
  if @model_1.save
    render :action => 'index'
  else
    render :action => 'new_model_1'
  end
end

end

I get this error:

ArgumentError in Auth userController#save_model_1
Unknown key(s): title

In new_model_1.html.erb:
<%= text_field :model_1, :title %>

Any ideas?

Thanks!

Is it possible to have a form_for :model_1, :model_2 ?

No, but you can have fields_for.

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