form_for 带有 json 返回
我目前有一个这样的表单:
<% 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| %>
但这似乎不起作用。
I currently have a form like this:
<% form_for @stem, :html => {:multipart => true} do |f| %>
<%= f.file_field :sound %>
<% end %>
This outputs (essentially):
<form method="post" id="new_stem" class="new_stem" action="/stems">
<input type="file" size="30" name="stem[sound]" id="stem_sound">
</form>
However I'm planning to use jQuery's ajaxForm plugin here and would like the new stem to be returned in JSON format. I know if the form's action was "/stems.json" this would work, but is there a parameter I can put into the form_for call to ask it to return JSON?
I tried doing
<% form_for @stem, :html => {:multipart => true, :action => '/stems.json'} do |f| %>
but this didn't appear to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决了问题
solves the problem
只需指定数据类型:
Just specify the data-type:
更干净:
even cleaner: