padrino:同名的子应用程序和控制器会产生冗余 url

发布于 2025-01-03 03:32:54 字数 1342 浏览 5 评论 0原文

我有一个 padrino 项目。

我创建了一个名为“用户”的子应用程序。

我还有一个名为 user 的模型和一个名为 users 的控制器来处理路由。

Users.controllers :users do

问题是生成和响应的网址是

app.com/users/users/index 等等,

除非我去每个动作并映射它

get :index, :map => '/' do

有更好的方法吗?

我真的不想将操作放在应用程序的 app.rb 中..即使效果很好。我喜欢分离。

有没有类似的

Users.controllers :users do
    map '/'
end

命名约定,我可以遵循它来创建一个响应我的应用程序根 URL 的默认控制器?

我想将其保留在用户控制器中,以便我可以使用

捆绑包中包含的 users_index 等 Gems:

activemodel (3.2.1)
activerecord (3.2.1)
activesupport (3.2.1)
arel (3.0.0)
bcrypt-ruby (3.0.1)
builder (3.0.0)
bundler (1.0.21)
haml (3.1.4)
http_router (0.10.2)
i18n (0.6.0)
mail (2.3.0)
mime-types (1.17.2)
multi_json (1.0.4)
padrino (0.10.6.c)
padrino-admin (0.10.6.c)
padrino-cache (0.10.6.c)
padrino-core (0.10.6.c)
padrino-gen (0.10.6.c)
padrino-helpers (0.10.6.c)
padrino-mailer (0.10.6.c)
polyglot (0.3.3)
rack (1.4.1)
rack-protection (1.2.0)
rack-test (0.6.1)
rake (0.9.2.2)
sass (3.1.13)
shoulda (2.11.3)
sinatra (1.3.2)
sinatra-flash (0.3.0)
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.31)
url_mount (0.2.1)

如果当我的应用程序名称与我的控制器名称匹配时我必须映射控制器中每个操作的路径,那很好。我只是想知道是否有一种方法可以通过控制器为我的所有操作设置基本路径或根路径。

谢谢

I have a padrino project.

I've created a sub app called "users".

I also have a model called user and a controller called users to handle the routing.

Users.controllers :users do

The issue with that is that the urls being produced and being responded to are

app.com/users/users/index
etc

unless I go to each action and map it

get :index, :map => '/' do

Is there a better way of doing this?

I don't really want to put the actions in the app.rb for the app.. even though that works great. I like having the separation.

Is there anything like

Users.controllers :users do
    map '/'
end

Is there a naming convention that I can follow to create a default controller that would response to my apps root url?

I'd like to keep it in the users controller so that I can use the users_index etc

Gems included by the bundle:

activemodel (3.2.1)
activerecord (3.2.1)
activesupport (3.2.1)
arel (3.0.0)
bcrypt-ruby (3.0.1)
builder (3.0.0)
bundler (1.0.21)
haml (3.1.4)
http_router (0.10.2)
i18n (0.6.0)
mail (2.3.0)
mime-types (1.17.2)
multi_json (1.0.4)
padrino (0.10.6.c)
padrino-admin (0.10.6.c)
padrino-cache (0.10.6.c)
padrino-core (0.10.6.c)
padrino-gen (0.10.6.c)
padrino-helpers (0.10.6.c)
padrino-mailer (0.10.6.c)
polyglot (0.3.3)
rack (1.4.1)
rack-protection (1.2.0)
rack-test (0.6.1)
rake (0.9.2.2)
sass (3.1.13)
shoulda (2.11.3)
sinatra (1.3.2)
sinatra-flash (0.3.0)
sqlite3 (1.3.5)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.31)
url_mount (0.2.1)

If I have to map the path for each action in the controller when my app name matches my controller name, that's fine. I was just wondering if there was a way to set the base or root path for all my actions via the controller.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光清浅 2025-01-10 03:32:54
#padrino-core-0.10.6.c/lib/padrino-core/application/routing.rb

#around line 655
#method parse_route

#right after unless controller.empty? i added the following which works in my case

   if controller.last.downcase == app_name.downcase and map.blank?
    controller = controller.slice(0, -2) unless controller.length == 1
    controller_path = controller.join("/")
    path.gsub!(%r{^\(/\)|/\?}, "")
    map = File.join(controller_path, path)
end

因此,现在如果我有一个名为 Users 的应用程序和一个名为 Users 的控制器来处理路由,我可以只说 /users 或 /users/new 等,而不是 /users/users/new 。

再说一遍,我对此很陌生,所以我不知道这是否是处理此问题的最佳方法。我可以在每条路线中手动设置地图,但这会很烦人。

我希望 DAddYE 能够重视这一点并提供更好的建议。

#padrino-core-0.10.6.c/lib/padrino-core/application/routing.rb

#around line 655
#method parse_route

#right after unless controller.empty? i added the following which works in my case

   if controller.last.downcase == app_name.downcase and map.blank?
    controller = controller.slice(0, -2) unless controller.length == 1
    controller_path = controller.join("/")
    path.gsub!(%r{^\(/\)|/\?}, "")
    map = File.join(controller_path, path)
end

So now if I have an application called Users and a controller called Users to handle the routes, I can just say /users or /users/new etc instead of /users/users/new.

Again, I'm very new to this, so I have no idea if this is the best way to handle this. I could have just set the map manually in each route, but that would be very annoying.

I'm hoping that DAddYE can weight in on this and provide a better recommendation.

梦开始←不甜 2025-01-10 03:32:54

您可以直接使用:

get "/" do
end

You can use directly:

get "/" do
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文