开发者

before_filter not inheriting from parent controller correctly?

开发者 https://www.devze.com 2023-02-01 20:46 出处:网络
Sorry if this may be a stupid question but I\'m unable get my filters to inherit the way the Rails 3 documentation is saying it should.

Sorry if this may be a stupid question but I'm unable get my filters to inherit the way the Rails 3 documentation is saying it should.

Specifically I have an Admin controller that was generated via:

rails generate controller admin

I added only a single action to the admin controller, the before filter & the private filter method

class AdminController < ApplicationController

  before_filter require_admin_creds

  def index
  end

private

  def require_admin_creds
    unless current_user && current_user.admin?
        flash[:error] = ...
        redirect_to ....
    end
  end
end

I next then created my nested resources under the admin section with:

rails generate s开发者_开发问答caffold admin/model

While my admin index is indeed getting the filter, the admin/model index (or any other actions) are not. What is happening under the hood here that I must have excluded?

Thanks in advance.


Make require_admin_creds a protected method, not private.


Did you change:

Admin::ModelController < ApplicationController 

to

Admin::ModelController < AdminController

?

This creates the inheritance, not placing the model controller into the admin namespace.


Double-check your syntax. You have:

before_filter require_admin_creds

but I think that should be:

before_filter :require_admin_creds

where you use a symbol, rather than a variable/method name.

0

精彩评论

暂无评论...
验证码 换一张
取 消