提交方法在 rails 中不起作用
Submit method don't work in rails
我需要将提交按钮替换为 "link_to"。
#View
<%= form_for :task, remote: true, id: 'create_form' do |f| %>
....
<%= link_to 'OK', '', id: 'submit_link' %>
<% end %>
#CoffeeScript
ready = ->
$("#submit_link").click (event) ->
$("#create_form").submit()
$(document).ready ready
$(document).on "page:load", ready
点击触发效果很好,但是"submit()"方法不起作用,我不知道为什么。
我也尝试添加 "event.preventDefault()",但没有任何改变。
我认为您需要像这样设置表单的 ID
<%= form_for :task, remote: true, html: { id: 'create_form' } do |f| %>
http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for
或者,只使用 form_for
生成的表单 ID,它应该是 new_task
#CoffeeScript
ready = ->
$("#submit_link").click (event) ->
$("#new_task").submit()
$(document).ready ready
$(document).on "page:load", ready
我需要将提交按钮替换为 "link_to"。
#View
<%= form_for :task, remote: true, id: 'create_form' do |f| %>
....
<%= link_to 'OK', '', id: 'submit_link' %>
<% end %>
#CoffeeScript
ready = ->
$("#submit_link").click (event) ->
$("#create_form").submit()
$(document).ready ready
$(document).on "page:load", ready
点击触发效果很好,但是"submit()"方法不起作用,我不知道为什么。 我也尝试添加 "event.preventDefault()",但没有任何改变。
我认为您需要像这样设置表单的 ID
<%= form_for :task, remote: true, html: { id: 'create_form' } do |f| %>
http://apidock.com/rails/ActionView/Helpers/FormHelper/form_for
或者,只使用 form_for
生成的表单 ID,它应该是 new_task
#CoffeeScript
ready = ->
$("#submit_link").click (event) ->
$("#new_task").submit()
$(document).ready ready
$(document).on "page:load", ready