问题描述
||
我有控制器:
class GroupRequestsController < ApplicationController
def update
@group_request = GroupRequest.find(params[:id])
respond_to do |format|
if @group_request.update_attributes(params[:group_request])
format.js
else
format.js
end
end
end
我认为我有:
<button type=\"button\" class=\"button positive tiny\">Add</button>
<button type=\"button\" class=\"button tiny\">Ignore</button>
如何单击这些按钮,以添加或忽略作为决策参数来远程调用控制器的更新方法?
谢谢
解决方法
使用单独的表格。
-form_for :group_request,:remote => true do |f|
=f.hidden_field :decision,\"Add\"
%button{:type => \"button\",:class => \"...\"} Add
-form_for :group_request,\"Ignore\"
%button{:type => \"button\",:class => \"...\"} Ignore
我使用HAML语法,因为如果您不使用HAML,则应该使用。这是发送值的唯一一致方式。 Button标记具有\“ value \”属性,但是并非所有主流浏览器都支持它,因此您不能依赖它。不幸的是,这意味着您必须做一些烦人的样式才能使按钮彼此相邻显示。
我唯一想到的另一种选择是使用纯JS来使按钮的行为类似于表单,但是我不建议这样做,因为它不会优雅地降级。