列出可安装 Rails 3.1 引擎的“rake routes" [英] Listing 'rake routes' for a mountable Rails 3.1 engine

查看:18
本文介绍了列出可安装 Rails 3.1 引擎的“rake routes"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于 Rails 3.1 的可安装引擎,我想列出引擎的路线.

I'm working on a mountable engine for use with Rails 3.1, and I want to list the engine's routes.

我使用以下方法创建了引擎:

I created the engine using:

$ rails plugin new rails_blog_engine --mountable

并编辑了test/dummy/config/routes"文件以读取:

And edited the 'test/dummy/config/routes' file to read:

Rails.application.routes.draw do
  mount RailsBlogEngine::Engine => "/blog"
end

...和配置/路由"阅读:

...and 'config/routes' to read:

RailsBlogEngine::Engine.routes.draw do
  resources :posts
end

我想列出为 ':posts' 生成的路由,但不清楚如何执行此操作.当我运行rake app:routes"时,我只得到/blog"路由:

I want to list the routes generated for ':posts', but it's not clear how I can do this. When I run 'rake app:routes', I get only the "/blog" route:

$ rake app:routes
rails_blog_engine    /blog    {:to=>RailsBlogEngine::Engine}

当我运行rake routes"时,出现错误:

When I run 'rake routes', I get an error:

$ rake routes
rake aborted!
Don't know how to build task 'routes'

如何查看 ':posts' 的路线?我可以在不重写相关 rake 任务的情况下做到这一点吗?

How can I see the routes for ':posts'? Can I do this without rewriting the relevant rake tasks?

推荐答案

如果你从标准 Rails 3.1.0 复制代码 rake routes 任务到您的 Rakefile 中,并将顶部更改为:

If you copy code from the standard Rails 3.1.0 rake routes task into your Rakefile, and change the top part to read:

task :routes => 'app:environment' do
  Rails.application.reload_routes!
  all_routes = RailsBlogEngine::Engine.routes.routes

...用你的引擎名称替换 RailsBlogEngine,然后你可以通过运行得到一个基本的路由列表:

...replacing RailsBlogEngine with the name of your engine, then you can get a rudimentary list of routes by running:

rake routes

请注意,在 Rails 3.1.1 及更高版本中,您需要一个 较新版本的 rake 路由 任务.

Note that in Rails 3.1.1 and later, you'll need a newer version of the rake routes task.

这篇关于列出可安装 Rails 3.1 引擎的“rake routes"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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