开发者

Rails3 routing: Resource with namespace

Is it possible to define a namespace parameter when defining my routes, like this:

resource :account, :namespace => :account do
    resources :comments
end

So /account/comment calls Account::Co开发者_开发知识库mmentsController instead of just CommentsController. Just as a note, the :namespace-option above does NOT seem to work.

I can of course just add :controller => 'account/comments' to the comments resources, but having a lot of nested resources, this is not very DRY.

Is there better way?

Thanks guys - you rock!


Okay, after some digging around I seem to have found a solution:

resource :account, :controller => 'account' do
    scope :module => 'account' do
        resources :comments
        ...
    end
end

This results in:

/account/comments being linked to Account::CommentsController while still being able to acccess the regular CRUD-methods using /account

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜