[英]rails get data from coffee to controller
I have some controller code like this to update the workorder.wostatus_id field. 我有一些像这样的控制器代码来更新workorder.wostatus_id字段。
def changestatus
@workorder = Workorder.find(params[:id])
@workorder.update_attributes(params[:wostatus_id])
render nothing: true
end
And the coffee script that ends up executing changestatus: 最后执行changestatus的coffee脚本:
receive: (event, ui) ->
alert $(ui.item).attr('change_url')
alert $(this).data('wostatus-id')
$.ajax
type: 'PUT'
url: "http://localhost:5000/workorders/13/changestatus"
data:
wostatus_id: 3
I have hard coded the url and wostatus_id while trying to get this working. 在尝试使此工作正常进行时,我已经对url和wostatus_id进行了硬编码。
But, the following line isn't getting the 3 from the coffee: 但是,以下行没有从咖啡中获取3:
@workorder.update_attributes(params[:wostatus_id])
If I hard code the line to this, it works to update the wostatus to 3: 如果我对此进行硬编码,它将wostatus更新为3:
@workorder.update_attribute :wostatus_id, '4'
Thanks in advance! 提前致谢!
This bit of your CoffeeScript: 您的CoffeeScript的这一部分:
data:
wostatus_id: 3
Should give you a params
that looks like this: 应该给你一个看起来像这样的
params
:
{ :wostatus_id => 3 }
So when you say: 所以当你说:
@workorder.update_attributes(params[:wostatus_id])
you're really saying: 你真的是在说:
@workorder.update_attributes(3)
and that doesn't really make much sense. 那真的没有多大意义。 You need to give
update_attributes
a key and a value: 您需要给
update_attributes
一个键和一个值:
@workorder.update_attributes(:wostatus_id => params[:wostatus_id])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.