Uninitialized Constant <ControllerName>

119 views
Skip to first unread message

David Ribeiro

unread,
Apr 28, 2008, 5:58:05 AM4/28/08
to resource_controller
Hi,

I'm back because I could'nt figured out what is causing me a NameError
in a newly added controller. I would like to know what kind of
mistakes can cause a Uninitialized Constant <ControllerName> error. In
my case, I'm using the Deep Nesting branch and after doing:

script/generate scaffold_resource Webnew name:string title:string
display_on_navbar:boolean archived:boolean
script/generate scaffold_resource Article webnew_id:references
title:string abstract:text

adding to webnew model: <has_many :articles>
adding to article model: <belongs_to :webnew> and
<has_many :contents, :as => :content>

mapping the routes as follow:
map.resources :webnews do |webnew|
webnew.resources :articles, :has_many => :contents

and content is a polymorphic resource

So, I know I've made a mistake but I'm not able to see it, if someone
could enumerate reasons that causes this type of error...

thank you..

Sean Schofield

unread,
Apr 28, 2008, 1:20:32 PM4/28/08
to resource_controller
First of all I think you can simplify your routing to this:

map.resources :webnew, :has_many => contents

You also need to add a little something to you controller. Try adding
this to your webnews_controller.rb

belongs_to :content_holdable, :polymorphic => true

I'm just guessing at the "content_holdable" part. The exact wording
should be whatever you call it in your polymorphic association.

HTH,

Sean

David Ribeiro

unread,
Apr 28, 2008, 3:08:42 PM4/28/08
to resource_controller
Hi Sean,

Actually I've this already for a different nested structure. The
problem is that I'm not able to replicate the same behavior with my
webnews.
This is the structure page->info->content:

Controllers:

class PagesController < ResourceController::Base
actions :all, :except => [:new, :edit, :create, :update, :destroy]
end
class InfosController < ResourceController::Base
belongs_to :page
actions :all, :except => [:new, :edit, :create, :update, :destroy]
end
class ContentsController < ResourceController::Base
belongs_to [:page, :info], [:webnew, :article]
actions :all, :except => [:new, :edit, :create, :update, :destroy]
end

These controllers are working fine (and you can see that I have
already an association for my new structure for the Contents
Controller)
The same should be working with webnew->article->content:

class WebnewsController < ResourceController::Base
actions :all, :except => [:new, :edit, :create, :update, :destroy]
end
class ArticlesController < ResourceController::Base
belongs_to :webnew
actions :all, :except => [:new, :edit, :create, :update, :destroy]
end

Additionally the models are:

class Page < ActiveRecord::Base
has_many :infos
validates_presence_of :name, :title
...
end
class Info < ActiveRecord::Base
belongs_to :page
has_many :contents, :as => :content
end
class Content < ActiveRecord::Base
belongs_to :content, :polymorphic => true
end
class Webnew < ActiveRecord::Base
has_many :articles
...
end
class Article < ActiveRecord::Base
belongs_to :webnew
has_many :contents, :as => :content
end

In the end, the routing should be:
# Pages
map.resources :pages do |page|
page.resources :infos, :has_many => :contents
end
# Webnews
map.resources :webnews do |webnew|
webnew.resources :articles, :has_many => :contents
end

Am I thinking wrongly?

Thank you..

David

David Ribeiro

unread,
Apr 29, 2008, 3:39:01 PM4/29/08
to resource_controller
Ok... seems that webnews is seen by the framework or the plugin as a
protected name... I change it to webnevv and it is working now.
Reply all
Reply to author
Forward
0 new messages