我需要制作一个按钮来销毁对象。而不是破坏它显示字段
inex.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 %>
devices_controller.rb
def destroy
@device = Device.find(params[:id])
@device.destroy
respond_to do |format|
format.html { render action: "destroy" }
format.json { head :no_content }
end
end
路线.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 %>
这很好用