Bilal Ahmed
Bilal Ahmed

Reputation: 433

Model level method to call in before_filter

I am working in rails 2, I have a model level method, which i want to call in before_filter. How can i do this? I tried this way, but its not working

before_filter :LmsUser.can_edit_update, :only => [:new, :create, :edit, :update, :destroy]

Upvotes: 2

Views: 858

Answers (1)

georgebrock
georgebrock

Reputation: 30043

You should add a method to your controller and use that as the before filter. For example:

class MyController < ApplicationController
  before_filter :check_permissions,
                :only => [:new, :create, :edit, :update, :destroy]

  private
    def check_permissions
      unless LmsUser.can_edit_update
        # redirect_to, render, or raise
      end
    end
end

See the filters section of the Action Controller Overview guide for more information.

Upvotes: 3

Related Questions