Я хотел бы иметь дополнительные атрибуты для моей модели пользователя и не хочу создавать отдельную модель профиля.Я пытаюсь обновить пользовательские поля стандартным «update» из набора действий RESTful:
class UsersController < ApplicationController
before_filter :authenticate_user!
# ...
def update
@user = User.find(params[:id])
authorize! :update, @user
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
end
И все идет хорошо, за исключением того факта, что current_user может обновить профиль любого пользователя.Кажется, я не могу ограничить действия пользователя.Я пробовал:
can :update, User, :id => user.id
и
cannot :update, User # at all
без удачи.Использование Devise 1.5.0 и CanCan 2.0.0.alpha
Вот моя способность.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new(:role => nil) # guest user (not logged in)
can :access, :all
if user.admin?
can :manage, :all
else
can :read, Review
if user.customer?
can :update, User, :id => user.id
can [:create, :update, :destroy], Review, :user_id => user.id
end
end
end
end