I am using Ruby on Rails 3.
In my controller I have (can I have?!):
def action_name(variable_name)
...
end
How can I pass the value of the "variable_name" using this syntax
[...] :url => { :ac开发者_C百科tion => :action_name("name") } [...]
? Is it possible?
In view: :url => {:action => :action_name, :variable_name => 'dog'}
In controller:
def action_name
variable_name = params[:variable_name]
@something = Something.where(:name => variable_name)
#More code in this method
end
This code will pass variable_name as a part of querystring in URL: http://site.com/something?variable_name=dog
Obviously, don't use this approach for sensitive data, and use :session[:variable_name] instead.
I'm not sure this is possible. However, why don't you use the params hash instead to get that param?
I suggest you use session
or flash
. e.g.
def action1
session[:your_key] = some_object
redirect_to some_action_path
end
def action2
@some_object = session[:your_key]
# ...
end
精彩评论