Note that there are some explanatory texts on larger screens.

plurals
  1. POrails 4 mass assignment error with protected_attributes gem
    primarykey
    data
    text
    <p>I'm trying to add a user profile sub module to a user module but having some problems.</p> <p>Routes:</p> <pre><code>resources :users do resources :userprofiles end </code></pre> <p>userprofiles_controller.rb:</p> <pre><code>class UserprofilesController &lt; ApplicationController def edit @user = current_user @user.UserProfile ||= UserProfile.new @userprofile = @user.UserProfile end def update @user = current_user @user.UserProfile ||= UserProfile.new @userprofile = @user.UserProfile if @userprofile.update_attributes(:userprofile =&gt; params[:userprofile]) redirect_to @user flash[:notice] = "Changes saved." else render 'edit' flash[:notice] = "Error." end end end </code></pre> <p>user_profile.rb:</p> <pre><code>class UserProfile &lt; ActiveRecord::Base attr_accessible :first_name, :last_name, :summary belongs_to :user end </code></pre> <p>Error:</p> <pre><code>Can't mass-assign protected attributes for UserProfile: userprofile </code></pre> <p>Line:</p> <pre><code>if @userprofile.update_attributes(:userprofile =&gt; params[:userprofile]) </code></pre> <p><strong>EDIT</strong></p> <p>Form:</p> <pre><code>&lt;%= form_for([@user, @userprofile], url: user_userprofile_path(@user, @userprofile)) do |form| %&gt; &lt;%= form.label :first_name %&gt; &lt;%= form.text_field :first_name %&gt; &lt;%= form.label :last_name %&gt; &lt;%= form.text_field :last_name %&gt; &lt;%= form.label :summary %&gt; &lt;%= form.text_area :summary %&gt; &lt;%= form.submit "Update", class: "btn btn-block btn-primary" %&gt; &lt;% end %&gt; </code></pre> <p>Table:</p> <pre><code> create_table "user_profiles", force: true do |t| t.string "last_name" t.string "first_name" t.text "summary" t.integer "user_id", null: false t.datetime "created_at" t.datetime "updated_at" end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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