2012-12-17 62 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]

相關問題