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 = ActiveModel::Name.new(klass, false,
klass.name.sub("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.


On Aug 18, 9:44 pm, Ajaxy <alx.zinc...@gmail.com> wrote:
> Hello!
>
> 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: site.com/galleries/2/
> 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!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to