[英]How add url_for in custom method in Ruby
I am writing a custom form helper and i need a URL path declared in routes but i have this error: 我正在编写自定义表单帮助程序,并且我需要在路由中声明的URL路径,但是出现此错误:
module CustomFormHelpers
include ActionView::Helpers::TagHelper
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormOptionsHelper
include ActionView::Helpers::CaptureHelper
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::RawOutputHelper
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::UrlHelper
def tags
tags_path
end
end
in routes.rb
resources :tags
What do I need include in the module to work 我需要包含在模块中才能工作
Duplicate of using url_for in a lib folder module 在lib文件夹模块中重复使用url_for
short answer: 简短答案:
include Rails.application.routes.url_helpers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.