2012-05-25 31 views
0

我想使按鈕與自定義遠程操作 當我嘗試Rail3 button_to遠程自定義操作

<%= button_to "something", {:controller => :updates, :action => :new}, {:remote => true} %> 

它工作正常,但如果我改變:動作我自己定義的動作在控制器

<%= button_to "something", {:controller => :updates, :action => :destroy_all, :method => :delete}, {:remote => true} %> 

窗體中生成的路徑是錯誤的

<form action="/assets?action=destroy_all&controller=updates&method=delete" class="button_to" data-remote="true" method="post"> 

在updates_controll呃我已經定義:destroy_all

def destroy_all 
    #some spaghetti code 
end 

我做了什麼錯了?

+0

什麼是你的路由文件是什麼樣子? – Mischa

回答

2

查看API。該:method所屬的html_options,而不是在options

<%= button_to "something", {:controller => :updates, :action => :destroy_all}, {:remote => true, :method => :delete} %> 

您還需要在指向"updates#destroy_all"你的路由文件中添加的路由。

+0

Omg我忘了路線,thx! – Zaraka

+0

不客氣。 – Mischa

0

問題不在於更改方法名稱。您沒有正確傳遞選項。看到

action="/assets?action=destroy_all&controller=updates&method=delete" 

我thinl它不是你想要的。嘗試

<%= button_to "smth", {:controller => :updates, :method => :destroy_all}, {:remote => true, :method => :delete} %> 

<%= button_to "smth", '/updates/destroy_all', {:remote => true, :method => :delete} %> 

小心使用方法刪除=)

+0

':method =>:destroy_all'是錯誤的。除此之外,您的答案與我的答案相同。 – Mischa

+0

對不起。 :method =>:delete_all改爲:action =>:delete_all – dmr