#834 ✓resolved
Tomoaki Hayasaka

subsite views refer wrong controller

Reported by Tomoaki Hayasaka | October 18th, 2010 @ 06:23 AM | in Hobo 1.3 (Rails 3)

Changes in 8940e97ac437697f introduced a new bug which causes "uninitialized constant" and other things in subsite.

Test:

class Todo < ActiveRecord::Base
  hobo_model # Don't put anything above this
  fields do
    todo :string
    timestamps
  end
  def create_permitted?; true; end
  def update_permitted?; true; end
  def destroy_permitted?; true; end
  def view_permitted?(field); true; end
end

class Admin::TodosController < ApplicationController
  hobo_model_controller
  auto_actions :all
end

Go to "/admin/todos" then you'll get "NameError in Admin/todosController#index uninitialized constant TodosController". Stack trace follows:

activesupport (3.0.0) lib/active_support/inflector/methods.rb:124:in `block in constantize'
activesupport (3.0.0) lib/active_support/inflector/methods.rb:123:in `each'
activesupport (3.0.0) lib/active_support/inflector/methods.rb:123:in `constantize'
activesupport (3.0.0) lib/active_support/core_ext/string/inflections.rb:43:in `constantize'
/home/hayasaka/work/hobo/hobo/dryml/lib/dryml.rb:218:in `taglibs_for'
/home/hayasaka/work/hobo/hobo/dryml/lib/dryml.rb:100:in `page_renderer'
/home/hayasaka/work/hobo/hobo/dryml/lib/dryml.rb:71:in `empty_page_renderer'
/home/hayasaka/work/hobo/hobo/dryml/lib/dryml/railtie/page_tag_resolver.rb:13:in `find_templates'

Some methods including page_renderer call controller.controller_name to determine the controller name, but modules-part in it is stripped out (e.g. only "users" is returned for Admin::UsersController, not "admin/users").

Replacing all controller.controller_name calles (at 3 locations) with controller.class.name.sub(/Controller$/, '').underscore fixes above uninitialized constant, but I'm not sure it's a right solution or not, and it's also ugly:

diff --git a/dryml/lib/dryml.rb b/dryml/lib/dryml.rb
index 781f7fb..2be40ad 100644
--- a/dryml/lib/dryml.rb
+++ b/dryml/lib/dryml.rb
@@ -68,7 +68,7 @@ module Dryml
 
 
   def empty_page_renderer(view)
-    page_renderer(view, page_tag_identifier(view.controller.controller_name))
+    page_renderer(view, page_tag_identifier(view.controller.class.name.sub(/Controller$/, '').underscore))
   end
 
   def page_tag_identifier(controller_name, tag_name='')
@@ -89,7 +89,7 @@ module Dryml
 
 
   def page_renderer(view, identifier, local_names=[], controller_name=nil)
-    controller_name ||= view.controller.controller_name
+    controller_name ||= view.controller.class.name.sub(/Controller$/, '').underscore
     prepare_view!(view)
     if identifier =~ /#{ID_SEPARATOR}/
       identifier = identifier.split(ID_SEPARATOR).first
diff --git a/dryml/lib/dryml/railtie/page_tag_resolver.rb b/dryml/lib/dryml/railtie/page_tag_resolver.rb
index a041536..aec53e5 100644
--- a/dryml/lib/dryml/railtie/page_tag_resolver.rb
+++ b/dryml/lib/dryml/railtie/page_tag_resolver.rb
@@ -11,7 +11,7 @@ module Dryml
         tag_name = @controller.dryml_fallback_tag || name.dasherize + '-page'
         method_name = tag_name.to_s.gsub('-', '_')
         if Dryml.empty_page_renderer(@controller.view_context).respond_to?(method_name)
-          [ActionView::Template.new('', Dryml.page_tag_identifier(@controller.controller_name, tag_name),
+          [ActionView::Template.new('', Dryml.page_tag_identifier(@controller.class.name.sub(/Controller$/, '').underscore, tag_name),
                                     Dryml::Railtie::TemplateHandler, details)]
         else
           []

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Tags

Pages