Rails 没有通过“提交"按钮参数 [英] Rails is not passing the "commit" button parameter

查看:37
本文介绍了Rails 没有通过“提交"按钮参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新服务器上重新安装 Rails 应用程序.应用程序的一部分可以根据用户选择的按钮向两个方向之一分叉.这部分不起作用,当我查看日志时,我看到了我为表单提供的值,execept 用于 params 哈希的 commit 部分.这似乎是应用程序没有按预期工作的原因(因为 params[:commit] 中没有任何内容,但我不知道为什么不会传入提交;请求绝对是一个 POST请求,所有其他参数都在那里.

Reinstalling a Rails app on a new server. Part of the app can fork in one of two directions based on the button the user selects. This part isn't working, and when I look at the log I see the values that I gave the form, execept for the commit portion of the params hash. This seems to be why the app isn't working as expected (since there's nothing in params[:commit], but I have no idea why commit would not be passed in; the request is definitely a POST request, and all of the other parameters are there.

推荐答案

在提交时禁用按钮功能存在类似问题.我们通过在提交表单之前添加一个具有相同名称和值的隐藏输入字段来解决它.

Had a simular problem with a disable-button-on-submit feature. We solved it by adding a hidden input field with the same name and value before submitting the form.

function disableButtonAndSubmit()
{
  var input = $("<input type='hidden' />").attr("name", $(this)[0].name).attr("value", $(this)[0].value);
  $(this).closest('form').append(input);
  $(this).attr('disabled', 'disabled').html('Loading…');
  $(this).closest('form').submit();
}

$('#somewhere button').click(disableButtonAndSubmit);

这篇关于Rails 没有通过“提交"按钮参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆