Ich habe zwei Modelle, Reklamation und Firma. Beschwerde belongs_to
und accepts_nested_attributes
für Firma und Firma has_many
Beschwerden.Verschachtelte Attribute für Angehörige_zu Assoziationsschienen
# Models
class Complaint < ActiveRecord::Base
attr_accessible :complaint, :date, :resolved
belongs_to :user, :class_name => 'User', :foreign_key => 'id'
belongs_to :company, :class_name => 'Company', :foreign_key => 'id'
has_many :replies
accepts_nested_attributes_for :company
end
class Company < ActiveRecord::Base
attr_accessible :name
has_many :complaints, :class_name => 'Complaint', :foreign_key => 'id'
has_many :branches, :class_name => 'Branch', :foreign_key => 'id'
belongs_to :industry
end
In der Beschwerde-Controller versuche ich ein Unternehmen in der neuen Methode zu bauen.
In dem Formular habe ich ein Feld hinzugefügt, um dem Unternehmen ein Namensattribut hinzuzufügen.
# Complaint Form
<%= form_for(@complaint) do |f| %>
<% if @complaint.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@complaint.errors.count, "error") %> prohibited this complaint from being saved:</h2>
<ul>
<% @complaint.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :complaint %><br />
<%= f.text_area :complaint, :rows => 5 %>
</div>
<div class="field">
<%= f.label :date %><br />
<%= f.datetime_select :date %>
</div>
<% if current_user.try(:admin?) %>
<div class="field">
<%= f.label :resolved %><br />
<%= f.check_box :resolved %>
</div>
<% end %>
<%= fields_for :company do |company| %>
<div class="field">
<%= company.label :name, 'Company' %>
<%= company.text_field :name %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Das Formular übermittelt, aber nur die Reklamation wird gespeichert. Die Benutzereingabe für Firma wird ignoriert. Warum wird dadurch kein neues Unternehmen geschaffen?
Hallo @pjmil, ich bin vor dem gleichen problem.will Sie mir bitte starke Parameter Beanstandungs-Controller sagen? –
Hallo, ich habe das gleiche Problem. Wie hast du es behoben? – aashish