Topic: Missing Parameters Help

I have a form in a partial that sets a number of variable and calls the create method of my controller when it's submitted.  It sounds simple enough, but when I submit the form I get an undefined method stringify_keys error.  I think I understand why, when you look down to see parameters being passed there are none of the form fields I specified.  All of it is gone save the commit.

Here is the _form.rhtml:

<%= error_messages_for 'action' %>

<!--[form:action]-->

<div class="form-item">
<label for="action_description">Description</label><br/>
<%= text_area 'action', 'description', :cols => '60', :rows => '7' %>
<div class="description">A description of the action taken</div>
</div>

<div class="form-item">
<label for="action_user_id">Person</label><br/>
<%=
  @users = User.find(:all, :order => "name")
  collection_select( 'action', 'user_id', @users, :id, :name )
%>
<div class="description">The name of the person that took the action</div>
</div>

<div class="form-item">
<label for="action_effort">Effort</label><br/>
<%= text_field 'action', 'effort'  %>
<div class="description">The effort required in the action (hours)</div>
</div>

<div class="form-item">
<label for="action_date">Date</label><br/>
<%= date_select 'action', 'date'  %>
<div class="description">The Date the action was taken on</div>
</div>

<div class="form-item">
<%= hidden_field( 'action', 'task_id', :value => params[:task_id] ) %>
</div>

<!--[eoform:action]-->


And here is the view:
<h1 class='heading'>New Action</h1>

<%= start_form_tag :action => 'create' %>
  <%= render :partial => 'form' %>
  <%= submit_tag "Add an Action" %>
<%= end_form_tag %>

<%= link_to 'Back', :action => 'list' %>

Last edited by circuitshaman (2006-07-06 22:02:48)

If art interprets our dreams, the computer executes them in the guise of programs.

-SICP (Abelson, Sussman)

Re: Missing Parameters Help

Hmm, nothing stands out to me which would cause that. What's the "create" method look like in your controller? Does it have a line like this?

@task = Task.new(params[:task])

Railscasts - Free Ruby on Rails Screencasts

Re: Missing Parameters Help

Yes it does, here's the whole of the create:

def create 
    @action = Action.new(params[:action])
    if @action.save
      flash[:notice] = 'Action was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end

And here's the model just in case:

class Action < ActiveRecord::Base
  belongs_to :task
  belongs_to :user

  validates_presence_of :task_id, :user_id, :description, :effort, :date
  validates_numericality_of :effort

  def validate
  end
end

If art interprets our dreams, the computer executes them in the guise of programs.

-SICP (Abelson, Sussman)

Re: Missing Parameters Help

This is your problem:

    @action = Action.new(params[:action])

You are creating a new Action model here, but your form is designed for creating a new Task. If you really want to create an action instead of a task, alter the form accordingly (just replace "task" with "action" if the fields are correct).

Railscasts - Free Ruby on Rails Screencasts

Re: Missing Parameters Help

I'm sorry, I posted the wrong partial in the initial message.  I apologize to waste your time like that.  I've edited the first post to include the correct code.

If art interprets our dreams, the computer executes them in the guise of programs.

-SICP (Abelson, Sussman)

Re: Missing Parameters Help

That's okay.

The problem is the model is named Action and this conflicts with the ":action" parameter you set in the start_form tag. The :action hash containing the field values gets overridden by the other :action. The best solution would be to rename the model so you don't run into any other conflict. Not very fun I know. sad

Railscasts - Free Ruby on Rails Screencasts

Re: Missing Parameters Help

That makes sense.  Thanks a lot for your help.

If art interprets our dreams, the computer executes them in the guise of programs.

-SICP (Abelson, Sussman)