Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

controller_name is invalid when controller_path changes

#4901

For some reason controller_name was changed to return last part of controller_path:

controller_path.split("/").last

What fails when controller_path is not default, e.g:

class MeatsController < ActionController::Base
end

class SteaksController < MeatsController
  def self.controller_path
    self.superclass.controller_path
  end
end

irb(main):009:0> MeatsController.controller_name
=> "meats"
irb(main):010:0> SteaksController.controller_name
=> "meats"

Rails 2.x implementation is more proper and returns real controller_name:

@controller_name ||= self.class.name.demodulize.sub(/Controller$/, '').underscore

Reported by knapo · June 18th, 2010 @ 06:00 PM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: none

Activity

  1. deviated
    deviated

    Valid
    -tried this on irb 0.9.5 and it prints this out

    irb(main):014:0> Hello.say
    NoMethodError: undefined method say' for Hi:Class<br/>

    from (irb):11:in `say'
    from (irb):14
    from /usr/local/bin/irb:12:in `<main>'
    

    *replaced 'controller_path' with say (doesn't matter what say does) basically did the same thing like he did, and it fails where his
    succeeds.

    June 19th, 2010 @ 08:15 AM

  2. José Valim
    José Valim
    • Milestone cleared.
    • Assigned user set to José Valim

    Could you please provide a patch with tests?

    June 21st, 2010 @ 10:21 AM

  3. knapo
    knapo

    Will do tomorrow.

    June 21st, 2010 @ 10:08 PM

  4. knapo
    knapo

    There you go!

    I guess that new tests related to this stuff should be included into test/controller/new_base/base_test.rb not in test/controller/base_test.rb or both?

    June 22nd, 2010 @ 07:50 PM

  5. José Valim
    José Valim

    You can add tests to any. The general idea is, new_base holds tests for stuff added specifically on Rails 3. base_test is since Rails early days. If you want me to pick one, I would say: go test/controller/base_test.rb :)

    June 22nd, 2010 @ 08:26 PM

  6. knapo
    knapo

    The reason I chose test/controller/new_base/base_test.rb is that I noticed that many tests (inc. controller_path, and controller_name related) in this file are duplicated between both test files (rewritten to new TestUnit syntax) with ones from test/controller/base_test.rb. So I thought that test/controller/base_test.rb is gonna to be replaced with new_base/base_test.rb :)

    June 22nd, 2010 @ 09:47 PM

  7. Repository
  8. Jeremy Kemper