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'
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 the Shopify App gem Webhooks controller you will need to be running Rails 4.2.6.
Try putting routes in this order:
post '/webhooks/receive', to: 'webhooks#receive'
mount ShopifyApp::Engine, at: '/'
Rails routes are matched in the order they are specified, so if you
have a resources :photos above a get 'photos/poll' the show action's
route for the resources line will be matched before the get line. To
fix this, move the get line above the resources line so that it is
matched first.
So in order for your own route to take precedence over the one that is defined in the ShopifyApp gem, you need to define it before mounting the ShopifyApp engine.
Moving your own route post '/webhooks/receive', to: 'webhooks#receive' before mount ShopifyApp::Engine, at: '/' should fix the issue.
Refer to Rails Routing from the Outside In for more info.
Related
My apps work fine in development mode on my localhost. But when i deploy my apps to Heroku i have an error like this :
/app/app/controllers/api/v1/Associations/associations_controller.rb:1:in `<top (required)>': uninitialized constant Api::V1::Associations (NameError)
I dont know whats wrong with my code. In my controller i have defined the class name like below :
class Api::V1::Associations::AssociationsController < Api::V1::ApiController
I already put this code on my application.rb but still no luck:
config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
I have routes like below :
namespace :api do
namespace :v1, :defaults => {:format => :json} do
namespace :associations do
get "/index" => "associations#index"
post "/create" => "associations#create"
post "/join" => "associations#join"
resources :associations_groups
resources :group_joined_by_springs
resources :group_created_by_springs
end
end
end
Everything works fine in my local using development mode. I cannot figure out how to solve this errors. I hope someone could help me.
P/s : I already looked all the solution provided on this site.
Edit (Rake routes)
Below is my routes for Associations
api_v1_associations_index GET /api/v1/associations/index(.:format) api/v1/associations/associations#index {:format=>:json}
api_v1_associations_create POST /api/v1/associations/create(.:format) api/v1/associations/associations#create {:format=>:json}
api_v1_associations_join POST /api/v1/associations/join(.:format) api/v1/associations/associations#join {:format=>:json}
move your api directory in to the app directory and remove this setting from application.rb - config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
All subdirectories of app in the application and engines present at boot time. For example, app/controllers. They do not need to be the default ones, any custom directories like app/workers belong automatically to autoload_paths.
From http://guides.rubyonrails.org
ruby -v = 2.1.6p336
rails -v = 4.2.1
MySQL --version = 14.14
New to programming and Rails. Going through tutorials.
did rails generate controller welcome index.
Rails Server - localhost:3000 shows Welcome aboard page.
Change config/routes.rb file... un-comment out root 'welcome#index' (got rid of the #. (line 8)
Rails Server - localhost:3000 shows error.
----------copied from localhost:3000------------------------------------------
ExecJS::ProgramError in Welcome#index
Showing c:/row/dev/readit/app/views/layouts/application.html.erb where line #6 raised:
TypeError: Object doesn't support this property or method
Rails.root: c:/row/dev/readit
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___173287605_49138164'
commented the root 'welcome#index' out again, and I have the Welcome Aboard page back.
If I execute localhost:3000/index
I get a routing error. No route matches [GET] "/index"
I have:
controllers/welcome_controller.rb
views/welcome/index.html.erb
this is the start of the config/routes.rb file -----------------
Rails.application.routes.draw do
get 'welcome/index'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'welcome#index'
How do I get the config/routes.rb file to display the views/welcome/index.html.erb file?
Does this have anything to do with the MySQL socket I'm suppose to put in the config/database.yml ? Because I don't what to put there.
It looks like there is an error at line 6 on "application.html.erb". If you want to create a hyperlink from that page to the "root" page, you should use the following view helper:
<%= link_to "Home", root_path %>
When the page is rendered and you check the HTML code using the Chrome's inspector, you will see that above code is converted to:
Home
In your app/views/layouts/application.html.erb, try changing the line:
<%= javascript_include_tag 'application', data-turbolinks-track => true %>
To this (removing the data-turbolinks-track => true):
<%= javascript_include_tag 'application' %>
That might fix it. You shouldn't remove the entire line as it's likely you'll need JS available in your layout at some point in the project :)
Hope it helps!
I fixed it by renaming my [It may not sound correct but it worked for me , give it a try]
app/views/layouts/application.html.erb
TO
app/views/layouts/default.html.erb
I hope it works for you as well
I have a definition in routes.rb that is something like this:
namespace :admin do
resources :users do
resources :email_addresses, controller: 'email_addresses'
end
end
The two controllers that exist are Admin::UsersController and EmailAddressesController. The problem I'm seeing is that once I deploy the app to production, trying to access any of the links for the email addresses resource results in a 404 and an uninitialized constant error for Admin::EmailAddressesController. For whatever reason, this isn't happening in my development environment.
Here's the output from my production environment log:
Started GET "/admin/users/3/email_addresses/new" for 192.168.206.6 at 2013-08-21 10:00:43 -0700
ActionController::RoutingError (uninitialized constant Admin::EmailAddressesController):
Here it is in my development environment working just fine:
Started GET "/admin/users/1/email_addresses/new" for 127.0.0.1 at 2013-08-21 10:03:04 -0700
Processing by EmailAddressesController#new as JS
Strange, right?
Here is an example of the link that I'm using that results in an error (once clicked):
link_to "Add Email Address", new_admin_user_email_address_path(user)
UPDATE: It seems as though the issue may be related to the issue mentioned in this bug report: https://github.com/rails/rails/issues/5798 . Question is, how do I explicitly reference the non-namespaced controller in controller: ?
I have a rails app with a cappuccino front end that I am trying to deploy onto Heroku.
The app works fine when I run it on localhost using WEBrick, but when I push onto Heroku I get the error message ActionController::RoutingError (No route matches "/"):
Here is the contents of the routing file:
CappcourceWs::Application.routes.draw do
resources :transaction_logs
resources :users
end
Is there a route that I have failed to define?
Doesn't look like a heroku-specific problem. My first guess is you need to add a root route, such as:
CappcourceWs::Application.routes.draw do
root :to => 'users#login'
resources :transaction_logs
resources :users
end
...or whatever the appropriate action/view is in your case.
So I am getting a 500 server error when attempting to bring up a rhtml page in rails. When I start the WEBrick server, I get the welcome to rails homepage. The name of the app is hello. I generated the controller from the command line and it looks like
class HelloController < ApplicationController
def there
end
end
I have my view (there.rhtml) in views/hello/there.rhtml. However the http://localhost:3000/hello/there gets a 500 sever error. I am currently running this on a vista box. Any ideas?
Have you defined the route ? It is defined in routes.rb . Also you can try checking the development logs to see what exactly is the issue .
could post the error log message? as Nm suggested it can be a route problem and if it is try to add this route in routes.rb file
map.connect '/hello/there', :controller => 'hello', :action => 'there'