Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 销毁方法不起作用,而是显示方法实现(Rails)_Ruby On Rails_Methods - Fatal编程技术网

Ruby on rails 销毁方法不起作用,而是显示方法实现(Rails)

Ruby on rails 销毁方法不起作用,而是显示方法实现(Rails),ruby-on-rails,methods,Ruby On Rails,Methods,我需要做一个按钮来摧毁这个物体。 它显示字段而不是销毁 inx.html.erb <%= link_to image_tag("/images/glossy_green_button.png"), device , { :html => { :method => :delete}, :controller => :devices, :action => 'destroy',:id => device.id, :onclick => 'return co

我需要做一个按钮来摧毁这个物体。 它显示字段而不是销毁

inx.html.erb

<%= link_to image_tag("/images/glossy_green_button.png"), device , { :html => { :method =>  :delete}, :controller => :devices, :action => 'destroy',:id => device.id, :onclick => 'return confirm(\'Are you sure?\');' }, :method => :turnon %>
routes.rb

device GET    /devices/:id(.:format)      devices#show
       PUT    /devices/:id(.:format)      devices#update
       DELETE /devices/:id(.:format)      devices#destroy
感谢你对我所犯错误的任何想法。 非常感谢。 D

更新:

<%= button_to "Delete", device ,  :method => :delete %>
:删除%>

这很好

您使用的是哪个版本的Rails?为什么到方法调用的
链接如此复杂?它可以简单地重写。请尝试以下方法:

<%= link_to image_tag("/images/glossy_green_button.png"), device , :method => :delete,  :confirm => "Are you sure?"
:删除,:确认=>“确定吗?”

您使用的是哪个版本的Rails?为什么到
方法调用的
链接如此复杂?它可以简单地重写。请尝试以下方法:

<%= link_to image_tag("/images/glossy_green_button.png"), device , :method => :delete,  :confirm => "Are you sure?"
:删除,:确认=>“确定吗?”

破坏性行动应作为表单提交执行-

改为使用按钮(传递:方法:删除)并适当设置按钮样式


或者尝试此
:delete,:class=>:destroy%>

破坏性操作应作为表单提交执行-

改为使用按钮(传递:方法:删除)并适当设置按钮样式


或者试试这个
:delete,:class=>:destroy%>

Rails 3.2.8版,非常复杂,因为我知道,你的答案仍然显示没有删除,而且
:confirm=>“你确定吗?”
因为某种原因被破坏了
“return confirm(\'you sure?\');”),:方法=>:删除%>
,虽然简化了,但仍然不起作用。可能问题出在图像标签中?现在是什么问题?显示生成的标记。问题与显示方法相同,而不是删除方法。因此,它显示了设备的所有字段,带有按钮“Edit”和“Back”,Rails版本3.2.8,非常复杂,因为尝试一切使其工作,有点绝望,我知道…您的回答仍然显示没有删除,而且
:confirm=>“您确定吗?”
由于某种原因被破坏
“返回确认(\'you sure?\');”,:方法=>:删除%>
,虽然简化了,但仍然不起作用。可能问题出在图像标签中?现在是什么问题?显示生成的标记。问题与显示方法相同,而不是删除方法。因此,它用按钮“Edit”和“Back”显示设备的所有字段。它可以工作,但现在它不会问“你确定吗?”
:delete,:class=>:destroy,:confirm=>“你靠岸了吗?”%%>
它可以工作,但现在它不会问“你确定吗?”
:delete,:class=>:destroy,:confirm=>“你靠岸了吗?”%%>