Egor Malkevich
Egor Malkevich

Reputation: 1536

Rails cancan gem for not restfull controller

Is it possible to use cancan load_and_authorize_resource for Controller with different name then model?

I mean:

Controller name -> EntityPropertiesController

Model name -> Property

Upvotes: 1

Views: 40

Answers (1)

Egor Malkevich
Egor Malkevich

Reputation: 1536

I don't found good way. So there is work around solution

class EntityPropertiesController < ApplicationController
  before_filter :authenticate_user!

  def index
    check_permission
  end

  def new
    check_permission
    ...
  end

  def create
    check_permission
    ...
  end

  ...

  protected

  def check_permission
    not_found unless (current_user.admin? || current_user.moderator?)
  end
end

Upvotes: 1

Related Questions