如何使用移动键盘“Go”获取而不是POST?

时间:2017-02-11 11:52:54

标签: javascript jquery ruby-on-rails ruby mobile

当用户点击“开始”时,我们如何阻止POST而不是GET link_to next_challenge_path(challenge: {name: @challenge.name})

_form

<%= f.text_field :name %>
<%= link_to next_challenge_path(challenge: {name: @challenge.name}), id: "challenge-button" do %>
  Save
<% end %>

<script>
  $("#challenge-button").click(function() {
    $(this).attr("href", function() {
      return this.href + $('.form-control').val();
    });
  });
</script>

enter image description here

日志

2017-02-11T11:27:24.259207+00:00 app[web.1]: Started POST "/challenges" for 110.171.153.192 at 2017-02-11 11:27:24 +0000
2017-02-11T11:27:24.261219+00:00 app[web.1]: Processing by ChallengesController#create as HTML
2017-02-11T11:27:24.261272+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"ozneOQJPp3f91TrRdxUyc02iw7VSBdQ1iMRGhpnDq8KBPHwj4QUTiXrjMTCDy+9XtKatffpexzLKYTV4P8V+lDQ==", "challenge"=>{"name"=>"Test"}}
2017-02-11T11:27:24.272414+00:00 app[web.1]: Redirected to http://www.livetochallenge.com/signup

我正在使用link_to,因为我希望用户在能够提交之前在next_challenge_path上填写更多属性。

2 个答案:

答案 0 :(得分:0)

页面上有提交按钮,按下按钮会在按下时自动触发

看看这个链接有两种可能的解决方案 1.禁用go按钮 2.或者禁用表单提交操作

How can I prevent the Go button on iPad/iPhone from posting the form

答案 1 :(得分:0)

好的,我想通了。

Javascript不是最佳解决方案。

相反,我可以使用控制器create操作。添加条件,该条件表示属性是nil,然后重定向到next_challenge_path