问题
I'm using the form_for
helper and would like it to submit to an iframe.
<%= form_for(section, :target => 'new_section_frame') do |f| %>
...
<% end %>
I should then be able to call $('form').submit()
and have the form submit to the iframe. It would work except that the target isn't present in the output html. The Rails guide on form helpers doesn't have this particular example.
回答1:
Options for the form_for
helper that pertain to html have to be in the html key. Like so:
<%= form_for(section, :html => {:target=>'new_section_frame'}) do |f| %>
...
<% end %>
回答2:
This is way shorter and should work in recent rails versions:
<%= form_for(section, target: '_new') %>
来源:https://stackoverflow.com/questions/15412984/how-to-add-target-to-rails-form-helper