Forum: Ruby on Rails inheritance problem with controllers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
chris (Guest)
on 2006-03-09 00:47
i have a controller like this:

class SpoilageController < DataEntryController
  before_filter { check_access_key('_SP') }
...

and in the parent class is this:

class DataEntryController < ApplicationController

  def check_access_key(key)
    if  !@session[:user].admin &&
        !@session[:user].data_entry_access.to_s.upcase.include?(key)
      render :text=>'You dont have access to this function',
:layout=>true
      false # disallow
    end
  end
...

But it crashes, with this error:
undefined method `check_access_key' for SpoilageController:Class

Why can't the spoilage class see the function in its parent class?
whats going on?
Mark Reginald J. (Guest)
on 2006-03-09 01:24
(Received via mailing list)
chris wrote:

> class SpoilageController < DataEntryController
>   before_filter { check_access_key('_SP') }
> ...
> But it crashes, with this error:
> undefined method `check_access_key' for SpoilageController:Class

Try: before_filter { |controller| controller.check_access_key('_SP') }

--
We develop, watch us RoR, in numbers too big to ignore.
chris (Guest)
on 2006-03-09 02:56
Champion! worked.
This topic is locked and can not be replied to.