Re: Form for 2 models?

Justin To
Thu, 17 Jul 2008 19:13:28 -0000

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!
--
Posted via http://www.ruby-forum.com/.