2012-05-20 6 views
1

질량 할당 보호에 대해 다음과 같은 오류가 나타나는 이유를 알지 못합니다. 나는 때라도보호 속성을 질량 할당 할 수 없습니다 : password_confrimation

거짓 config.active_record.whitelist_attributes에 기기 구성 설정을 =이 있지만 모델과 컨트롤러

모든 아이디어에 대한 코드는?

 ActiveModel::MassAssignmentSecurity::Error in UsersController#create 
Can't mass-assign protected attributes: password_confrimation 
Rails.root: C:/Users/huzaifa.gain/My Documents/Aptana Studio 3 Workspace/blog 

Application Trace | Framework Trace | Full Trace 
app/controllers/users_controller.rb:7:in `new' 
app/controllers/users_controller.rb:7:in `create' 


Request 

Parameters: 
{"utf8"=>"?", 
"authenticity_token"=>"CIPrmS9ZZlgUELOMkAT6Htw1eLPMxmXRh7Ur7doeYcY=", 
"user"=>{"email"=>"huzi", 
"password"=>"[FILTERED]", 
"password_confrimation"=>"[FILTERED]"}, 
"commit"=>"Create User"} 


class UsersController < ApplicationController 
    def new 
    @user = User.new 
    end 

    def create 
    @user = User.new(params[:user]) 
    if @user.save 
     redirect_to_ articles_path, :notice => 'User successfully added.' 
    else 
     render :action =>'new' 
    end 
    end 

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

    def update 
    @user = User.find(parms[:id]) 
    if @user.update_attributes(params[:user]) 
     redirect_to articles_path, :notice => 'Updated user information successfully' 
    else 
     render :action => 'edit' 
    end 
    end 
end 


require 'digest' 
class User < ActiveRecord::Base 

    attr_accessor :email, :password , :password_confirmation 
    attr_accessible :email, :password , :password_confirmation 
    validates :email, :uniqueness => true, 
            :length => {:within => 5..50}, 
            :presence => true 

    validates :password, :confirmation => true, :length => { :within => 4..20 }, :presence => true, :if => :password_required? 

    has_one :profile 

    has_many :articles, :order => 'published_at DESC, title ASC', 
         :dependent => :nullify 
    has_many :replies, :through => :articles, :source => :comments 

    before_save :encrypt_new_password 

    def self.authenticate(email, password) 
    user = find_by_email(email) 
     return user if user && user.authenticated?(password) 
    end 

    def authenticated?(password) 
    self.hashed_password == encrypt(password) 
    end 


    def encrypt_new_password 
    return if password.blank? 
     self.hashed_password = encrypt(password)                                                                                                                
    end 

    def password_required? 
    hashed_password.blank? || password.present? 
    end 

def encrypt(string) 
    Digest::SHA2.hexdigest(string) 
end 


end 
+3

가능한 복제본 [rake db : seed thorwing 보호 된 속성을 대량 할당 할 수 없음] (http://stackoverflow.com/questions/10493640/rake-dbseed-thorwing-cant-mass-assign-protected-attributes) –

+1

@HolgerJust 이것이 중복 된 것 같지 않습니다. OP에 오타가있는 것처럼 보입니다. –

답변

5

나는 오타가 있다고 생각합니다. 귀하의 모델은 attr_accessible :email, :password , :password_confirmation입니다. 그러나 귀하의 양식은 password_confrimation을 철자 같이 보입니다.

:password_confrimation 

에 :

+0

이러한 오타 관련 질문을 제거하여 [스택 오버플로 정리 캠페인] (http://meta.stackexchange.com/q/167342)이있어 정말 도움이 될 수 있습니다! 이 질문에 가까운 표를 던지면서 조금 피칭해도 될까요? –

0
은에서 양식을 변경

그것은 오타

:password_confirmation 

.

관련 문제