2013-07-31 2 views
1

내가 4. 모든 레일 API를 구축하기 위해 노력하고있어 (쇼/삭제/생성) 잘 작동하지만 업데이트는 나에게 오류 제공 :루비에 레일 4 API - 갱신 유증 사용자

ActiveModel::ForbiddenAttributesError in Api::V1::UsersController#update

내 즉, 레일 바로해야한다 4.

내가 잊는 것 같아 - TESTUSER 패치를 통해 :

def update 
    @user = User.find_by_id(params[:id]) 
    if @user.nil? 
    logger.info("User not found.") 
    render :status => 404, :json => {:status => "error", :errorcode => "11009", :message => "Invalid userid."} 
    else 
    @user.update(params) 
    render :status => 200, :json => {:status => "success", :user => @user, :message => "The user has been updated"} 
    end 
end 

내가 http://localhost:3000/api/v1/users/3 내 POST 요청을 보내고 내가 이름을 보내고있다 : 업데이트 방법은 다음과 같이이다 ~을 허락하다 업데이트 될 매개 변수는 무엇입니까?

답변

2

는 단순히 @user.update_attributes(params.permit(:email, :username, :password))

@user.update(params) 을 대체 난 그냥 필요 4. 레일 구문을 잊었다