Topic: How to pass values to an action?

In a view I have:
<%= link_to "Accept Quest", :controller => 'quest', :action => 'accept_quest',
:user_id => "2", :quest_id => "24" %>

In the controller I have:
@acceptquest = QuestUser.new(params[:user_id]).save.

I can see the parameters in the log: Parameters: {"quest_id"=>"24", "action"=>"accept_quest", "controller"=>"quest", "user_id"=>"2"}

But I get error msg:
undefined method `stringify_keys!' for "2":String

Looking at the table all the columns are either an :int or :timestamp (I haven't set the timestamp value yet).

Any idea why I get this error?

Re: How to pass values to an action?

The problem is you are only passing the user_id to QuestUser.new and it expects a hash. Try this in your controller instead.

@acceptquest = QuestUser.new(:user_id => params[:user_id], :quest_id => params[:quest_id]).save

Last edited by ryanb (2006-07-05 14:03:51)

Railscasts - Free Ruby on Rails Screencasts

Re: How to pass values to an action?

ryanb wrote:

The problem is you are only passing the user_id to QuestUser.new and it expects a hash. Try this in your controller instead.

@acceptquest = QuestUser.new(:user_id => params[:user_id], :quest_id => params[:quest_id]).save

Thanks! That works perfectly.  Man, I've had a ton of trouble getting to this simple solution in irc & another forum.  I don't think I really asked in any significatly different way than here, but there ya go.