그래서 Rails를 사용하는 간단한 역할 기반 인증 시스템을 구현하려고하고 있으며 마지막 단계 변경 역할에 문제가 있습니다.Rails collection_select가 params 해시의 모든 값을 저장하지 않습니다.
role
은 user
표의 속성이며 string
유형이 있습니다.
일부 권한이있는 일부 사용자는 역할을 변경할 수있는 능력이 있습니다. view
에서
코드는 다음과 같습니다 users_controller
에서
<div>
<%= f.label :role, 'Role' %>
<%= f.collection_select :role, User::ROLES, :to_s, :humanize,
prompt: 'Select role' %>
</div>
update
방법은 다음과 같습니다
def update
@user = User.find(params[:id])
if @user.update(update_params) #update_params is method that returns permitted parameters
redirect_to @user
else
render :edit
end
end
문제 user[role]
이 양식을 제출 한 후 비어있는 것입니다.
모든 것이 "책"으로 제작되었습니다. 또한 Cancan을 사용하고 있지만 edit
및 update
의 경우는 load_and_authorize_resource :except => [:update, :edit]
으로 설정되어 있습니다.