Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble saving two models from a view using accepts_nested_attributes_for
    text
    copied!<p>I have two models. A company and a master_user which is a devise user. I get an unpermitted parameters: master_user when trying to create the company object in the create action of the company controller.</p> <p>Models are</p> <pre><code>company.rb class Company &lt; ActiveRecord::Base has_many :users has_one :master_user accepts_nested_attributes_for :master_user end master_user.rb class MasterUser &lt; ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable belongs_to :company end </code></pre> <p>Here is my company view</p> <pre><code>&lt;%= form_for(@company) do |f| %&gt; &lt;% if @company.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@company.errors.count, "error") %&gt; prohibited this company from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @company.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="field"&gt; &lt;%= f.label :name %&gt;&lt;br&gt; &lt;%= f.text_field :name %&gt; &lt;/div&gt; &lt;%= f.fields_for @company.master_user do |m_user| %&gt; &lt;div class="field"&gt; &lt;%= m_user.label :email %&gt; &lt;%= m_user.text_field :email %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= m_user.label :password %&gt; &lt;%= m_user.password_field :password %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= m_user.label :confirm_password %&gt; &lt;%= m_user.password_field :confirm_password %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>and the company controller</p> <pre><code># GET /companies/new def new @company = Company.new @company.build_master_user end # POST /companies # POST /companies.json def create puts "a" @company = Company.new(company_params) puts "b" respond_to do |format| if @company.save format.html { redirect_to @company, notice: 'Company was successfully created.' } format.json { render action: 'show', status: :created, location: @company } else puts "c" format.html { render action: 'new' } format.json { render json: @company.errors, status: :unprocessable_entity } end end end def company_params params.require(:company).permit(:id, :name, :isTrial, :employMax, master_user_attributes: [:id, :email, :password, :confirm_password, :company_id]) end </code></pre> <p>I'm permitting the parameters per the rails 4 requirement. But for some reason it is still rejecting my master_user </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload