ruby-on-rails – 在lib文件夹模块中使用url_for
发布时间:2020-12-16 20:15:44 所属栏目:百科 来源:网络整理
导读:我有一个名为“type”的字段和一个称为“value”的字段的模型.类型字段将决定如何在渲染之前解析“值”.我希望这可以容易地扩展,所以我在我的lib文件夹中放置了各种“格式化程序”类. 我的一个“格式化程序”调用url_for: class CustomTypeFormatter includ
我有一个名为“type”的字段和一个称为“value”的字段的模型.类型字段将决定如何在渲染之前解析“值”.我希望这可以容易地扩展,所以我在我的lib文件夹中放置了各种“格式化程序”类.
我的一个“格式化程序”调用url_for: class CustomTypeFormatter include ActionView::Helpers::TextHelper include ActionView::Helpers def show raw sanitize( auto_link( value ) ) end def get_url(page) url_for( :controller => :my_controller,:action => :show,:path => page.path ) end end 问题是,url_for正在提高此错误: undefined local variable or method `_routes' 我想我只是错过了一个包括.有人有什么想法应该是什么? **更新*** 这是堆栈跟踪的一部分: actionpack (3.0.7) lib/action_dispatch/routing/url_for.rb:131:in `url_for' actionpack (3.0.7) lib/action_view/helpers/url_helper.rb:99:in `url_for' 所以我认为它必须是一些ActiveDispatch依赖,虽然我无法弄清楚 解决方法
胜利!
include ActionView::Helpers include ActionDispatch::Routing include Rails.application.routes.url_helpers 通过http://apidock.com/rails/ActionController/UrlWriter (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |