开发者

Rails 3 passing parameter to new method

开发者 https://www.devze.com 2023-02-16 07:03 出处:网络
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:

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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消