Ruby on rails model and controllers inside of different namespaces

Posted by Nelson LaQuet on Stack Overflow See other posts from Stack Overflow or by Nelson LaQuet
Published on 2009-05-24T19:41:53Z Indexed on 2010/04/29 19:17 UTC
Read the original article Hit count: 332

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 http://stackoverflow.com/questions/903258/ruby-on-rails-model-inside-namespace-cant-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"}
                                DELE
        

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails