2016-04-21 66 views
2

我正在使用ShopifyApp寶石,它的WebhooksController中有一個叫做receive的動作。正如在這裏看到:Webhooks controller從寶石繼承控制器類

在我WebhooksController控制器我想這樣做來覆蓋receive行動如下:

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

我對我的WebhooksController路線是這樣的:

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

而由寶石引擎輸入的路線是:

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

我看到數據進來,但由於某種原因,它沒有打我的receive行動,停在我的pry,我不知道爲什麼。

Found this and tried it, but no luck.

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

有什麼想法?

這裏是我的日誌顯示發生的事情上:

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?' 

我的路線文件

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' 
+0

**我看到數據進來** - 請解釋你在哪裏看到這個?**但由於某種原因,它沒有打我的接收方法,停在我的撬,我不知道爲什麼** - 它是否停在'binding.pry'? – dp7

+0

我在控制檯中看到它,並沒有它沒有擊中'binding.pry'不知道爲什麼..我試過這個,但它沒有工作.. [覆蓋類中的Gem](http:// stackoverflow .com/questions/2688853/how-to-override-a-class-method-of-the-gem-in-rails-application) – ToddT

+0

你可以添加日誌嗎? – dp7

回答

2

後故障排除的兩天,我實現了自己的Gemspec是包括舊版本不包含他們調用方法軌..

我讓他們知道撞到我的版本4.2.5從4.2。 6現在它的工作..令人沮喪但解決..謝謝大家的支持!

如果有其他人遇到此問題,爲了使用Shopify App gem Webhooks控制器,您需要運行Rails 4.2.6。

0

嘗試把路線順序:

post '/webhooks/receive', to: 'webhooks#receive' 
mount ShopifyApp::Engine, at: '/' 
0

的Rails路線按照它們指定的順序進行匹配,所以如果你使用 有一個資源:上面的照片獲取'照片/民意調查'顯示行動的 路線的資源行將匹配之前得到線。到 解決這個問題,將獲取線移動到資源行上方,以便首先匹配 。

因此,爲了使自己的路線優先於在ShopifyApp寶石定義的,你需要安裝ShopifyApp引擎之前定義它。

移動你自己的路線post '/webhooks/receive', to: 'webhooks#receive'之前mount ShopifyApp::Engine, at: '/'應該解決這個問題。

有關更多信息,請參閱Rails Routing from the Outside In