简体   繁体   中英

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:


    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

short answer:

include Rails.application.routes.url_helpers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM