namespaces as "scope :module"


I've got Gallery resource with namespaces: /gallery/galleries_controller.rb /gallery/albums_controller.rb /gallery/photos_controller.rb and models Gallery::Gallery, Gallery::Album and Gallery::Photo in my / models/gallery/ folder

I want my Gallery work like standart resource: albums/3, but being incapsulated in own folders, so i write in routes.rb this rules:

scope :module => "gallery" do   resources :galleries do     resources :albums   end end

And then i've trouble using, i.e.

@gallery = Gallery::Gallery.find(1); redirect_to(@gallery);

undefined method `gallery_gallery_url'

-- but why `gallery_gallery_url' when i expect just `gallery_url' like it is in "rake routes"?

next time i write <% @gallery = Gallery::Gallery.find(1); %> <%= form_for @gallery do |f| %>

undefined method `gallery_galleries_path'

-- i need to manualy add :url option: <%= form_for @gallery, :url => galleries_path do |f| %>

What's wrong? What i have to do with this issue? Thanks for any help!

Spent a few hours looking through RoR sources and seems like i found some kind of solution: If we override property @_model_name in our models we can strip out "Gallery::" from it:

class Gallery::Gallery < ActiveRecord::Base   @_model_name = Gallery.model_name(self) end

And in module:

module Gallery   def self.table_name_prefix     'gallery_'   end

  def self.model_name(klass)     @_model_name =, false,"Gallery::", ""))   end end

And it works! Now "form_for(@gallery)" and "link_to(@gallery)" use "galleries_path" for action instead of non-existent "gallery_galleries_path"

The only thing i want to know now is - am i criminal now after doing theese practices? Is it legal to override this property for this reason? Thank you.