开发者

assigning parameters to a model in a link_to helper

开发者 https://www.devze.com 2023-03-14 22:05 出处:网络
if am trying to pass a parameter 开发者_StackOverflowthrough a link and assign it to a specific model. here is the code i\'m working with:

if am trying to pass a parameter 开发者_StackOverflowthrough a link and assign it to a specific model. here is the code i'm working with:

<%= link_to ( image_tag("item.png", :size => "50*50", :border=> 0, :alt => "item", :title => "item"), {:action => 'initialize_order', :frame_id => 1 }) %>

right now :frame_id is getting passed through as:

{"frame_id"=>"1"} 

i want the parameter to be assigned to the model :order, returning:

"order"=>{"frame_id"=>"1"}

i know the answer must be simple but i've searched for a while now.


try this in your url args:

{:action => 'initialize_order', :order => {:frame_id => 1 }}

alternatively, since you only have one parameter, just pass it as :id and assign it in the controller.

Even better, build your app using RESTful routes, with an orders_controller and an initialize method. If orders and frames have a parent-child relationship, then nest them in your resources. That way you can use all the path generators.

0

精彩评论

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