views:

64

answers:

2

I have a AR model inside a module

class Long::Module::Path::Model < ActiveRecord::Base
end

and want to use following routes (without the module names, because it's easier to write and remember)

resources :models

buts Rails 3 always wants to use a URL like

long_module_path_model_url

Is there are way to change this behavior?

Hope anyone out there can help me?

Mario

A: 
resources :your_looooooong_model_name, :as => :short

Would give you shorts_url, etc.

numbers1311407
Nope, sorry didn't worked for me... Got lots of routing errors now.
ream88
A: 

I'm a little curious why you're referencing a model when talking about routing which only handles the controller level; but this article should be helpful: R3 Controller Namespaces and Routing

"If you want to route /photos (without the prefix /admin) to Admin::PostsController, you could use:

scope :module => "admin" do
  resources :posts, :comments
end

"

If you'd like the named paths to change, you can use :as, as specified here: R3 Prefixing the Named Routes Helpers

So I'm guessing something along the lines of

1:

scope :module => 'long/module/path' do
   resources :model, :as => :model
end

or 2:

scope :module => 'long' do
  scope :module => 'module' do 
   scope :module => 'path' do
    resources :model, :as => :model
   end end end

Is what you're looking for.

Tim Snowhite
Nope, you didn't understand me ;) I want to access my models with model_path(@model), and not with long_module_path_model(@model). Seems not to be working.
ream88
Perhaps the revised version above is better.
Tim Snowhite