2012-12-17 99 views
2

am工作在Rails 2.3.8版本中 Hash => agent_list = [[5,“val”],[4,“val”],[3 , “VAL”],[1, “VAL”]]Ruby on Rails - 将链接作为参数传递给link_to_remote Rails 2

<%= link_to_remote "Click Here", 
     :url => { 
     :controller => "controller", 
     :action => "method", 
     :id => @p_id, 
     :hash_list => hash_list 
     }, 
     :method => 'post' %> 

链接生成是:

[HTTP://本地主机/控制器/方法/ 12 hash_list%5B%5D%5B %5D = 5 & hash_list%5B%5D%5B%5D = val & hash_list%5B%5D%5B%5D = 4 & hash_list%5B%5D%5B%5D = val & hash_list%5B%5D%5B%5D = 3 & hash_list%5B%5D%5B% 5D = VAL & hash_list%5B%5D%5B%5D = 1 & hash_list%5B%5D%5B%5D = VAL]

谁能告诉我什么是要达到这样的正确方法: HTTP://localhost/controller/method/12?hash_list = [hash_list]

这样我可以在我的控制器方法中将它用作params [:agent_list]。

P.S.对不起,如果它是一个nooby问题。

回答

1

在创建路线您routes.rb的动作,如果尚未创建,则:

<%= link_to "Click here", my_route_path(@obj, :hash => { :foo => "bar" }), :remote => true, :method => :post %> 

未经测试,但应该做的伎俩。如果您提供的是remote: true,那么它的URL看起来并不重要,散列应该位于您的控制器的params[:hash]中。

link_to_remote已在Rails 3+中弃用。

的Rails 2.3.8:

<%= link_to_remote "Click here", :url => my_route_path(@obj, :hash => { :foo => "bar" }), :method => :post %> 
+0

哎我在轨工作2.3.8。我在一个点,我不能升级到Rails 3.所以你可以修改上述相应的PL?因为我已经尝试过,但我仍然失去了一些东西。 – Gunner

+0

@Gunner编辑。 –

0

<%= link_to @item_link_name, show_item_path(item: {id: @item.id}) %>

产生http://localhost:3000/items/show_item?item%5Bid%5D=XXX

什么是控制器识别为params[:item][:id]

相关问题