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

问题描述

我正在研究可与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

...并且 config / routes显示为:

...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}

当我运行耙路线,我得到一个错误:

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

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

如何查看路线对于:职位?我可以在不重写相关rake任务的情况下执行此操作吗?

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

推荐答案

如果从标准Rails 3.1.0复制代码任务更改为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及更高版本中,您将需要任务。

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

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

10-10 18:22