1

我想用一个按钮提交两个表单。

下面如果我的代码: -

率.rb

belongs_to :target, :polymorphic => true
belongs_to :location

位置.rb

has_many :rates

事件.rb

has_many :rates, :as => :target

form.html.haml

= form_for [@event, @rate] do |form|
                    %ul
                        %li= form.radio_button :rate, "Excellent"
                        %li Excellent
                        %li= form.radio_button :rate, "Okay"
                        %li Okay
                        %li= form.radio_button :rate, "Poorly organized"
                        %li Poorly organized
                        %li= form.radio_button :rate, "Didn't happen"
                        %li Didn't happen

=form_for [@event.location, @rate] do |form|
                    %ul
                        %li= form.radio_button :rate, "Excellent"
                        %li Excellent
                        %li= form.radio_button :rate, "Okay"
                        %li Okay
                        %li= form.radio_button :rate, "Nothing special"
                        %li Nothing special

如何才能做到这一点 ?

4

1 回答 1

2

我今天处于同样的情况并做了:

在 form.html.haml 添加链接:(我在 ERB 中写过)

<%= link_to "Save", "#", :class => 'button_submit' %>

假设某些咖啡文件中的表单 ID 为“form1”和“form2”:

rate.js.coffee

jQuery ->
  $(".button_submit").live "click", (e) ->
    e.preventDefault()
    $("#form1").trigger "submit"
    $("#form2").trigger "submit"

而已!

于 2012-10-14T02:01:38.203 回答