Rails,如何提交带有文本链接的表单? [英] Rails, how do you submit a form with a text link?

查看:59
本文介绍了Rails,如何提交带有文本链接的表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使此表单正确提交.这是我到目前为止的内容:

I am trying to get this form to submit correctly. Here's what I have so far:

<% form_for(:user, :url => update_user_setting_path, :remote => true, :html => {:method => :post, :class => "search_form general_form"}) do |f| %> 

,按钮将显示以下代码:

and the button renders with this code:

<li><%= link_to raw("<span class='button approve'><span><span>SAVE</span></span></span>"), :action => 'create' %></li>

我正在使用动作创建,对吗?

I am using action create, is this correct?

这是呈现的表单标签:

<form method="post" data-remote="true" class="search_form general_form" action="/settings/2/update_user" accept-charset="UTF-8">

我想念什么?感谢您的帮助!

What am I missing? Thanks for your help!

推荐答案

否,您没有正确使用link_to.您需要使用Submit标记而不是link_to标记来提交表单,例如:

No, you are not using link_to properly. You need to use a submit tag to submit your form, not a link_to tag, for example:

<% form_for(:user, :url => update_user_setting_path, :remote => true, :html => {:method => :post, :class => "search_form general_form"}) do |f| %>
  ...
  <li><%= f.submit "Save" %></li>

如果要使用文本链接,则必须让javascript提交表单.例如,如果您使用的是jQuery,则可以执行以下操作:

If you want to use a text link you'll have to have javascript submit the form. For example, if you are using jQuery you could do the following:

<%= link_to 'Save', "#", :onclick=>"$('.search_form').submit()" %>

这篇关于Rails,如何提交带有文本链接的表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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