Ad

Inherit Controller Class From Gem

- 1 answer

I am using the ShopifyApp gem, which has an action called receive in its WebhooksController. As seen here: Webhooks controller

In my WebhooksController controller I am trying to override that receive action by doing the following:

class WebhooksController < ShopifyApp::WebhooksController
  def receive
    binding.pry
  end
end

My route to my WebhooksController is this:

webhooks_receive POST   /webhooks/receive(.:format)  webhooks#receive

And the route put in by the Gem engine is:

webhooks POST /webhooks/:type(.:format)  shopify_app/webhooks#receive

I see the data come in, but for some reason its not hitting my receive action and stopping at my pry and I'm not sure why.

Found this and tried it, but no luck.

I tried this solution too and it didn't work..

Any thoughts?

Here are the top of my logs showing what's happening:

Started POST "/webhooks/receive" for XX.XXX.37.116 at 2016-04-21 14:57:02 
+0000
Cannot render console from XX.XXX.37.116! Allowed networks: XXX.0.0.1, ::1, 
127.0.0.0/127.XXX.XXX.255

ActiveRecord::SchemaMigration Load (0.2ms)  SELECT "schema_migrations".* 
FROM "schema_migrations"

Processing by ShopifyApp::WebhooksController#receive as */*
Parameters: {"rate"=>{"origin"=>{"country"=>"US", "postal_code"=>"48615",   
"province"=>"MI", "city"=>"Breckenridge", "name"=>nil, "address1"=>"6760.. 
bunch of data removed for brevity}}}

Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.0ms)

NoMethodError (undefined method `variable_size_secure_compare' for   
ActiveSupport::SecurityUtils:Module):
shopify_app (7.0.2) lib/shopify_app/webhook_verification.rb:20:in   
`hmac_valid?'

And my routes file

Rails.application.routes.draw do
root :to => 'home#index'
mount ShopifyApp::Engine, at: '/'
resources :store
resources :shipping_methods

post '/webhooks/receive', to: 'webhooks#receive'
post '/billing_plans', to: 'billing_plans#save_plan', as: 'save_plan'
get '/activate_charge', to: 'billing_plans#activate_charge', as: 'activate'
post '/create_charge', to: 'billing_plans#create_charge', as: 
'create_billing_plan'
Ad

Answer

After two days of troubleshooting I realized their Gemspec was including an old version of rails that did not contain the method they were calling..

I let them know and bumped my version from 4.2.5 to 4.2.6 and now it works.. frustrating but solved.. thanks everyone for your support!

If anyone else comes across this, in order to use theon of rails that did not contain the method they were calling..

I let them know and bumped my version from 4.2.5 to 4.2.6 and now it works.. frustrating but solved.. thanks everyone for your support!

If anyone else comes across this, in order to use the Shopify App gem Webhooks controller you will need to be running Rails 4.2.6.

Ad
source: stackoverflow.com
Ad