Ruby on rails model and controllers inside of different namespaces

form-formodelnamespacesrubyruby-on-rails

OK. This is insane.

I'm new to RoR and I really want to get into it as everything about it that I have seen so far makes it more appealing to the type of work that I do.

However, I can't seem to accomplish a very simple thing with RoR.

I want these controlers:

/admin/blog/entries (index/show/edit/delete)
/admin/blog/categories (index/show/edit/delete)
/admin/blog/comments (index/show/edit/delete)
... and so on

And these models:

Blog::Entry    (table: blog_entries)
Blog::Category (table: blog_categories)
Blog::Comments (table: blog_comments)
... and so on

Now, I have already gone though quite a bit of misery to make this work. My first attempt was with generating scaffolding (I'm using 2.2.2). I generated my scaffolding, but had to move my model, then fix the references to the model in my controller (see Ruby on Rails model inside namespace can't be found in controller).

That is already a big of a pain, but hey, I got it to work. Now though form_for won't work and I cannot figure out how to use the url helpers (I have no idea what these are called… they are the automatically generated methods that return URLs to controllers associated with a model). I cannot figure out what their name is. My model is Blog::Entries. I have tried to mess with the route.rb's map's resource method, but no luck. When I attempt to use form_for with my model, I get this error

undefined method `blog_entries_path' for #<ActionView::Base:0xb6848080>

Now. This is really quite frustrating. I am not going to completely destroy my code's organization in order to use this framework, and if I cannot figure out how to accomplish this simple task (I have been researching this for at least 5 hours) then I simply cannot continue.

Are there any ideas on how to accomplish this?

Thanks

EDIT

Here are my routes:

             admin_blog_entries GET    /admin_blog_entries                  {:controller=>"admin_blog_entries", :action=>"index"}
   formatted_admin_blog_entries GET    /admin_blog_entries.:format          {:controller=>"admin_blog_entries", :action=>"index"}
                                POST   /admin_blog_entries                  {:controller=>"admin_blog_entries", :action=>"create"}
                                POST   /admin_blog_entries.:format          {:controller=>"admin_blog_entries", :action=>"create"}
           new_admin_blog_entry GET    /admin_blog_entries/new              {:controller=>"admin_blog_entries", :action=>"new"}
 formatted_new_admin_blog_entry GET    /admin_blog_entries/new.:format      {:controller=>"admin_blog_entries", :action=>"new"}
          edit_admin_blog_entry GET    /admin_blog_entries/:id/edit         {:controller=>"admin_blog_entries", :action=>"edit"}
formatted_edit_admin_blog_entry GET    /admin_blog_entries/:id/edit.:format {:controller=>"admin_blog_entries", :action=>"edit"}
               admin_blog_entry GET    /admin_blog_entries/:id              {:controller=>"admin_blog_entries", :action=>"show"}
     formatted_admin_blog_entry GET    /admin_blog_entries/:id.:format      {:controller=>"admin_blog_entries", :action=>"show"}
                                PUT    /admin_blog_entries/:id              {:controller=>"admin_blog_entries", :action=>"update"}
                                PUT    /admin_blog_entries/:id.:format      {:controller=>"admin_blog_entries", :action=>"update"}
                                DELETE /admin_blog_entries/:id              {:controller=>"admin_blog_entries", :action=>"destroy"}
                                DELETE /admin_blog_entries/:id.:format      {:controller=>"admin_blog_entries", :action=>"destroy"}
                           home        /                                    {:action=>"index", :controller=>"index"}
                                       /:controller/:action/:id
                                       /:controller/:action/:id.:format

That dosn't look right. Here is my routes.rb (comments removed):

ActionController::Routing::Routes.draw do |map|

  map.resources :admin_blog_entries

  map.home '', :controller => 'index'

  map.connect ':controller/:action/:id'
  map.connect ':controller/:action/:id.:format'
end

Best Solution

have you tried looking at the routes list that "rake routes" gives you? if your routes.rb is correct, it should show you the correct name for the blog entries route.

also, maybe this can help: http://www.coreywoodcox.com/2008/08/18/rails-namespaces-subdomains/.

edit:

well, then the correct way to call the route is admin_blog_entries_path instead of blog_entries_path.