rtfminc
rtfminc

Reputation: 6363

Rails 3 passing parameter to new method

Okay, am going nuts trying to get this to work. I want to pass information I need to the new action and it ain't working. I am in a view and using link_to with a path to create a new record:

<%= link_to "New", new_libation_path(:xid=> 123) %>

My routes table has: resources :libations

And in the libation_controller I have my new action...

def new
  puts params[:xid]    #This is nil!
  ...

What am I doing wrong? Maybe I should google how to use params in rails..

Upvotes: 8

Views: 11663

Answers (1)

Michelle Tilley
Michelle Tilley

Reputation: 159095

This looks right. Is the query string in the URL showing up as it should? Check on your rails console that app.new_libation_path(:xid => 123) is returning the correct URL, and that this URL is showing up in your HTML markup:

ruby-1.9.2-p136 :001 > app.new_user_path(:test => 'test')
 => "/users/new?test=test"

(from an app I had handy)

Upvotes: 20

Related Questions