Search code examples
ruby-on-railstrello

Rails overwriting params value


I'm trying to up receive updates on my Trello model when a change occurs, which I'm using their webhooks for. The problem is that one of the parameter's name is "action", which seems to be overwritten by Rails depending on the value in the Routes.rb. Is there any way to avoid this or do I just have to live with it?


Routes.rb

  match "/trello" => "trello_updates#index", via: [:get,:post]

Webhook reponse

Parameters: {"model"=>{...},"action"=>"index"}

Solution

  • You can write a middleware in initializers and update the params coming from trello webhooks. like below -

    class TrelloWebhooks
    
      def initialize(app)
        @app = app
      end
    
      def call(env)
        request = Rack::Request.new(env)
        trello_action = request.params['action']
        request.update_param('trello_action', trello_action)
        status, headers, response = @app.call(env)
        [status, headers, response]
      end
    
    end
    
    Rails.application.config.middleware.use 'TrelloWebhooks'