- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Rails 3.2.15 应用程序,在 routes.rb
顶部安装了一个引擎,如下所示:
mount Service::Engine => '/'
rake routes
输出)中有这个路由,它在引擎中不存在:
manager_account GET /manager/accounts/:id(.:format) manager_accounts#show
spec_helper.rb
中包含了应用程序和引擎的 url_helpers :
RSpec.configure do |config|
config.include Service::Engine.routes.url_helpers, type: :feature
config.include Rails.application.routes.url_helpers, type: :feature
end
manager_account_path(account)
时,出现以下错误:
ActionController::RoutingError:
No route matches {:action=>"show", :controller=>"manager_accounts", :id=>...
main_app.manager_account_path(account)
那么它就会成功,但我真的很想避免每次都指定它。有什么方法可以设置它,我可以使用我的 url_helpers 以便如果引擎中不存在路由,它会回退到基本应用程序?
最佳答案
看起来您正在尝试在主应用程序中测试您的引擎代码。我建议使用引擎提供的虚拟应用程序来测试您的引擎代码。
根据 Rails guide :
When an engine is generated, there is a smaller dummy application created inside it at test/dummy. This application is used as a mounting point for the engine, to make testing the engine extremely simple. You may extend this application by generating controllers, models or views from within the directory, and then use those to test your engine.
The test directory should be treated like a typical Rails testing environment, allowing for unit, functional and integration tests.
关于ruby-on-rails - 将 url_helpers 用于 Rails 引擎和 Rspec 中的基本应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19867202/
我尝试从 Module 类内部访问 URL helper。这是我的代码: module Station class Plugins @@plugins = [] unless define
我想知道如何使用 Rails.application.routes.url_helpers 访问引擎路由. 我有一个工厂对象,它创建一个包含动态生成的 url 的字符串。目前,我可以使用 Rails.
在 Controller 中,我调用如下服务: MyService.call 在 MyService.call方法我想使用一个 url 助手: Rails.application.routes.url
在我的 Rails 应用程序中有一个部分包含在新操作和编辑操作之间共享的表单: .... 这些操作是 Controller (称为customers)命名空间(称为admin)的,如果尝试运行代码
我的 Rails3 项目中有以下路线: match "/blog/:permalink" => "posts#show", :as => :post 当我通过这样的 View 链接到我的帖子时: 帖
我有一个 Rails 3.2.15 应用程序,在 routes.rb 顶部安装了一个引擎,如下所示: mount Service::Engine => '/' 在测试我的应用程序时,我想为我的引擎使用
在我的 Rails 应用程序中,一个 lib 类用于接收电子邮件。电子邮件接收者类解析电子邮件并使用 HTTP 响应将其发送到应用程序 Controller 。代码如下所示: uri = 'htt
我正在构建一个 Serializer for Collection+Json ,我正在编写一个 API 作为示例。我在使用 Rails.application.routes.url_helpers 时
当尝试为使用 Rails 实现的服务生成 YARD 文档时,我收到以下警告: $ yardoc [warn]: in YARD::Handlers::Ruby::MixinHandler: Undoc
我正在开发 Rails 3.1.1。 在模型中包含 url_helpers 会导致保存模型时出现 ArgumentError。 class Medium cause ArgumentError
我正在开发一个 Ruby gem(针对 Rails 4),我希望能够在其中使用 url 助手。所以我尝试添加 include Rails.application.routes.url_helpers,
我是一名优秀的程序员,十分优秀!