Search code examples
ruby-on-rails-3.2before-filter

Rails- Can I do a params.merge in a before_filter in ApplicationController


I want to add a parameter to the params hash on every request which is why I'm working at the ApplicationController level. I have something like the following which is not working.

class ApplicationController < ActionController::Base
  before_filter :tagOn

    def tagOn  
      v = findValueToTagOn() #find somehow what will be the value to tag on. Is dynamic.
      Rails.logger.info("PARAMS BEFORE: #{params.inspect}")
      params.merge(:my_id => v.to_s)
      Rails.logger.info("PARAMS AFTER: #{params.inspect}")
    end

Right now both my before and after output is the same which tells me the merging to params is not working. Any ideas how to do this? Thanks.

Using Rails v 3.2.3


Solution

  • Looks like you are one character off.

    params.merge!(:my_id => v.to_s)