Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5997719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:18:14+00:00 2026-05-23T00:18:14+00:00

I’m migrating a Rails 2 app over to Rails 3, and hitting a major

  • 0

I’m migrating a Rails 2 app over to Rails 3, and hitting a major problem. I’ve got a method being called in my application.html.erb called check_author_role which is throwing

undefined local variable or method `check_author_role'

The check_author_role method is defined in a file called lib/authenticated_system.rb.

I learned that Rails 3 no longer autoloads the lib/ directory, so I’ve added the following lines to config/application.rb:

config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]

I thought that would do it. However I’m still getting the error. This implies that one of the following is going on:

  1. config/application.rb isn’t being loaded properly
  2. My autoload syntax is wrong
  3. I’m defining the method in a deprecated way
  4. I’m calling the method in a deprecated way

I’ve been at this for a few hours now and can’t make heads or tails of it. All was fine before the Rails 3 update. Anyone have some suggestions?

Here’s what lib/authenticated_system.rb looks like:

module AuthenticatedSystem
  protected

  def check_author_role
    check_role('author')
  end    

  def check_role(role)
    if logged_in? && @current_user.has_role?(role)
      true
    else
      access_denied
    end
  end
end

And here’s what app/layout/application.html.erb looks like:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head profile="http://www.w3.org/2005/10/profile">
    ...
  </head>
  <body>
    ...
    <% if check_author_role %>
      ...
    <% end %>
    ...
  </body>
</html>

And lastly, here’s config/application.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

Bundler.require(:default, Rails.env) if defined?(Bundler)

module MyApp
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)
    config.autoload_paths += %W(#{config.root}/lib)
    config.autoload_paths += Dir["#{config.root}/lib/**/"]

    ...

  end
end 

I admit that I’m fuzzy on how helper methods work, especially in Rails 3. Here’s what I’m noticing.

In lib/authenticated_system.rb:

# Inclusion hook to make methods
# available as ActionView helper methods.
def self.included(base)
  base.send :helper_method, :current_user, :logged_in?, :check_role, :check_administrator_role, :check_author_role, :has_role, :has_administrator_role, :has_author_role
end

I’ll be honest and say I don’t really know what base.send is all about.

In app/controllers/application.rb I have the following:

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time

  include AuthenticatedSystem

Again, I’m afraid I don’t fully understand what exactly this code is up to.

Curiously I notice that I also have a file in the same directory with a very similar name: app/controllers/application_controller.rb. It’s almost empty, with only three lines.

class ApplicationController < ActionController::Base
  protect_from_forgery
end

My hypothesis: app/controllers/application_controller.rb is the new Rails 3 file, while app/controllers/application.rb has my old code from my Rails 2 site. I’ll test this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:18:15+00:00Added an answer on May 23, 2026 at 12:18 am

    Is the AuthenticatedSystem module mixed in to your application_controller?

    If so, then methods there will not be automatically available in the views.

    You need to add something like:

    helper :check_author_role
    

    … in your application_controller, after mixing in the AuthenticatedSystem module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.