加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 带有json返回的form_for

发布时间:2020-12-17 04:36:46 所属栏目:百科 来源:网络整理
导读:我目前有一个这样的表格: % form_for @stem,:html = {:multipart = true} do |f| %%= f.file_field :sound %% end % 这输出(基本上): form method="post" id="new_stem" class="new_stem" action="/stems"input type="file" size="30" name="stem[sound]"
我目前有一个这样的表格:
<% form_for @stem,:html => {:multipart => true} do |f| %>
<%= f.file_field :sound %>
<% end %>

这输出(基本上):

<form method="post" id="new_stem" class="new_stem" action="/stems">
<input type="file" size="30" name="stem[sound]" id="stem_sound">
</form>

但是我打算在这里使用jQuery的ajaxForm插件,并希望以JSON格式返回新的词干.我知道如果表单的动作是“/stems.json”这可行,但是有一个参数我可以放入form_for调用,要求它返回JSON吗?

我试过了

<% form_for @stem,:html => {:multipart => true,:action => '/stems.json'} do |f| %>

但这似乎不起作用.

解决方法

只需指定数据类型:
= form_for(@stemp,:remote => true,:html => {:'data-type' => 'json',:multipart => true})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读