如何更改控制器内的参数?
当我点击接受时,它将通过状态已批准,但如果diff <= 0
将状态更改为已拒绝
查看
<%= link_to 'Accept', friend_path(s, :request => {:status => 'Accepted'}), method: :put %>
进入这个
if diff <= 0
req_params[:status] = "Rejected"
@request.update(req_params)
end
end
private
def req_params
params.require(:request).permit(:status)
end
end
答案 0 :(得分:1)
要修改状态参数,您需要执行以下操作:
params[:request][:status] = 'Rejected'
or
req_params[:request][:status] = 'Rejected'
因为您的请求采用了这样的参数:
Parameters => { some_param => 'Something', required => { permited1 => 'bla',
permited2 => 'bla2',
... } }
我希望能帮到你