2013-06-23 2 views
-1

나는 이것이 일반적인 오류라는 것을 알고 있지만 사용자 등급이 <입니다. ActiveRecord :: Base attr_protected : 제공자, : uid, : 이름, : 내 사용자 모델의 이메일 : 여전히이 오류가 발생합니다.보호 된 속성을 지정할 수 없습니다 : 전자 메일

ActiveModel::MassAssignmentSecurity::Error in UsersController#update 

Can't mass-assign protected attributes: email 
Rails.root: /Users/ewalker/Documents/alift 

Application Trace | Framework Trace | Full Trace 
app/controllers/users_controller.rb:19:in `update' 
Request 

Parameters: 

{"utf8"=>"✓", 
"_method"=>"put", 
"authenticity_token"=>"F+5itYNqPddn4usVgIJwzG+PSz50Up7mqZs50x3f9Ho=", 
"user"=>{"email"=>"[email protected]"}, 
"commit"=>"Sign in", 
"id"=>"1"} 

내 사용자 컨트롤러 :

class UsersController < ApplicationController 



def show 
    @user = User.find(params[:id]) 
end 

def index 
    @users = User.all 
end 

def edit 
    @user = User.find(params[:id]) 
end 

def update 
    @user = User.find(params[:id]) 
    if @user.update_attributes(params[:user]) 
    redirect_to @user 
    else 
    render :edit 
    end 
end 
end 

사용자 모델 :

class User < ActiveRecord::Base 
attr_protected :provider, :uid, :name, :email 

has_many :posts, dependent: :destroy 

    def self.from_omniauth(auth) 
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| 
     user.provider = auth.provider 
     user.uid = auth.uid 
     user.name = auth.info.name 
     user.oauth_token = auth.credentials.token 
     user.oauth_expires_at = Time.at(auth.credentials.expires_at) 
     user.save! 
    end 
    end 
end 

및 편집 양식 :

<%= form_for(@user) do |f| %> 
    <%= f.label :email %> 
    <%= f.text_field :email %> 
    <br /> 
    <%= f.submit "Sign " %> 
<% end %> 
다음

은 세부입니다

감사합니다.

답변

4

attr_protected 오류가 예상 될 수 있도록 대량 할당을 방지합니다. attr_accessible :email이 원하는 것일 수 있습니다. 그러면 질량 할당에 속성이 설정됩니다.