Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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..

like image 951
rtfminc Avatar asked Mar 13 '11 07:03

rtfminc


1 Answers

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)

like image 183
Michelle Tilley Avatar answered Nov 16 '22 02:11

Michelle Tilley