Rails 3路线和模块 [英] Rails 3 routes and modules

查看:72
本文介绍了Rails 3路线和模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模块内部有一个AR模型

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

但是Rails 3总是想要使用这样的URL

buts Rails 3 always wants to use a URL like

long_module_path_model_url

是否可以更改此行为?

希望有人可以帮助我吗?

Hope anyone out there can help me?

马里奥(Mario)

推荐答案

我有点好奇,为什么您在谈论仅处理控制器级别的路由时引用模型?但本文应该会有所帮助: R3控制器命名空间和路由

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

如果要将/ photos(不带前缀/ admin)路由到Admin :: PostsController,则可以使用:

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

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

如果要更改命名路径,可以使用:as ,如下所示: R3为命名路由助手添加前缀

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

或2:

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

您正在寻找的东西。

这篇关于Rails 3路线和模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆