How can I globally override a rails url helper?

前端 未结 4 2184
时光取名叫无心
时光取名叫无心 2020-12-06 12:30

I needed to add a simple change to foo_path, so I did this:

module ApplicationHelper
  # [...]

  def foo_path(foo, options = {})
    option         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 13:26

    Looks like you are facing wrong way. You would better add :bar param in your route, like:

    get :foo, :bar => "bar"
    

    Otherwise, please provide more descriptive details about your problem.

    Edit.

    Here is the solution(basic on your post update):

    class ApplicationController < ActionController::Base
      def foo_path(foo, options = {})
        options.merge!(bar: foo.some_attribute)
        super
      end  
      helper_method :foo_path
    end
    

提交回复
热议问题