2013-12-21 7 views
0

레일스를 처음 사용합니다. 특히 Rails 3과 4 사이의 변화에 ​​대처할 때 나는 RailsCast와 MHartl의 튜토리얼을 배웠다.레일 4 레일의 StrongAttributes 캐스트 # 274

나는 성공적 RailsCast 번호 274의 코드는 아래에 링크 된 문제의 답을 사용하여 작업을 가지고 : ActiveModel::ForbiddenAttributesError in PasswordResetsController#update

내 관심이 수정, 미래의 문제 나 취약 떠날는 보안이 될 것입니다 그렇지 않으면. 이것을 할 수있는 "올바른"방법이 있다면 나는 알고 싶다. 내 코드 블록은 다음과 같습니다.

class PasswordResetsController < ApplicationController 
    def create 
    user = User.find_by_email(params[:email]) 
    user.send_password_reset if user 
    redirect_to root_url, :notice => "Email sent with password reset instructions." 
    end 

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

    def update 
    @user = User.find_by_password_reset_token!(params[:id]) 
    if @user.password_reset_sent_at < 2.hours.ago 
     redirect_to new_password_reset_path, :alert => "Password reset has expired." 
    elsif @user.update_attributes(params.require(:user).permit(:password, :password_confirmation)) 
     redirect_to root_url, :notice => "Password has been reset." 
    else 
     render :edit 
    end 
    end 
end 

답변

0

먼저 매개 변수를 설정해야합니다.

@model.update(model_params) 

대량 할당이 레일에서 멋진 일이지만 당신은 당신이 보호해야 : 당신이 업데이 트를 수행 할 때 다음

private 
def model_params 
    params.require(:model).permit(:list :all :your :attributes) 
end 

는 같은 것을 사용 클래스 내에서 private 메소드를 정의

도움이 되길 바랍니다.

+0

엄청난 것이 내가 찾고있는 것입니다. – Puchembo