Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.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
根据jquery条件修改Rails模型元素_Jquery_Ruby On Rails - Fatal编程技术网

根据jquery条件修改Rails模型元素

根据jquery条件修改Rails模型元素,jquery,ruby-on-rails,Jquery,Ruby On Rails,我的申请表中有一个复选框。在提交表单时,我需要查看是否选中了复选框,如果是,我需要修改模型的属性。以下是我的代码,它不起作用: $("#customer_submit").click(function(){ if ($("#default_check").is(':checked')){ <%current_merchant.has_default = true <%current_merchant.save%> } $(“#客户_提交”)。单击(函数(){

我的申请表中有一个复选框。在提交表单时,我需要查看是否选中了复选框,如果是,我需要修改模型的属性。以下是我的代码,它不起作用:

$("#customer_submit").click(function(){
if ($("#default_check").is(':checked')){
    <%current_merchant.has_default = true
    <%current_merchant.save%>
}
$(“#客户_提交”)。单击(函数(){
如果($(“#默认#u检查”)。为(':checked')){

您正在混合客户端脚本和服务器端代码

在将代码发送到客户端之前,正在执行中的ruby代码。 它周围的javascript在客户端执行

实际上,您正在向浏览器发送要执行的JavaScript代码:

$("#customer_submit").click(function(){
  if ($("#default_check").is(':checked')){
  }
});
是的,你做得根本不对:)


实际上,您要做的是向服务器发送一个AJAX调用或其他形式的消息,以将模型更改持久化。

然后向处理模型更改的控制器方法发送帖子是正确的方法吗?现在更新了我的答案。.抱歉,所有编辑。.但事实如此:)