两种形式,一是提交轨

问题描述:

我有一个问题:两种形式,一是提交轨

我的第一种形式

<div class="authform"> 
    <h3>Edit <%= resource_name.to_s.humanize %></h3> 
    <%= form_for(current_user, :url => registration_path(current_user), :html => { :method => :put, :role => 'form', :id => "form1"}) do |f| %> 
    <%= devise_error_messages! %> 
    <div class="form-group"> 
     <%= f.label :nombre %> 
     <%= f.text_field :nombre, :autofocus => true, class: 'form-control' %> 
    </div> 
     <div class="form-group"> 
     <%= f.label :email %> 
     <%= f.email_field :email, class: 'form-control' %> 
     </div> 
    </div> 
     <% end %> 
</div> 

第二种形式是

<%= simple_form_for(@auto, html: { method: :post, id: :subir }) do |f| %> 
    <%= f.error_notification %> 

    <div class="form-inputs"> 
     <%= f.association :region %> 
     <%= f.association :ciudad %> 
     <%= f.association :marca %> 
     <%= f.input :modelo %> 
     <%= f.input :version %> 
    </div> 
    <% end %> 

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

auto.coffee

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

我需要这个来保持真相,并没有意识到这一点。我做错了什么,请帮忙。

问候。

+0

看一看http://stackoverflow.com/questions/19260755/how-to- submit-two-forms-with-one-submit-button-with-rails-and-javascript – Arvind

+0

你面临的问题是什么?出了什么问题? –

建议只使用一种形式。但是,如果你想在rails中使用多种形式,你可以使用语义形式与语义嵌套的字段,这将帮助你使用多种形式,也可以用关系来保存数据。 https://github.com/ryanb/nested_form供您参考。

修改的形式就是这样,

<%= semantic_form_for current_user, :url => registration_path(current_user), :html => { :method => :put, :role => 'form', :id => "form1"} do |f| %> 
    <%= devise_error_messages! %> 
    <div class="form-group"> 
    <%= f.label :nombre %> 
    <%= f.text_field :nombre, :autofocus => true, class: 'form-control' %> 
    </div> 
    <div class="form-group"> 
    <%= f.label :email %> 
    <%= f.email_field :email, class: 'form-control' %> 
    </div> 
    <%= f.semantic_fields_for(@auto, html: { method: :post, id: :subir }) do |form| %> 
    <%= form.error_notification %> 
    <div class="form-inputs"> 
     <%= form.association :region %> 
     <%= form.association :ciudad %> 
     <%= form.association :marca %> 
     <%= form.input :modelo %> 
     <%= form.input :version %> 
    </div> 
    <% end %> 
<% end %> 

,你也应该在用户模式,

class User < ActiveRecord::Base 
    has_many :posts 
    accepts_nested_attributes_for :posts, :reject_if => :all_blank, :update_only => true, :allow_destroy => true 
    end