2012-05-25 29 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