i have deployed an app to heroku(finance tracker under "ROR developer course" from udemy.com). The login button works fine but when i click on the signup button, it gives me this error
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
I have ran heroku run rake db:migrate successfully.
I used devise gem for authentication.
Pls any idea someone??....thanks
Edit
From log:
2016-10-26T17:46:19.965045+00:00 heroku[router]: at=info method=GET path="/users/sign_up" host=johnuzoma-finance-tracker.herokuapp.com request_id=9b928dfe-66be-47b5-933b-3d5b6cf3a899 fwd="197.210.25.210" dyno=web.1 connect=0ms service=19ms status=500 bytes=1754
2016-10-26T17:46:19.950321+00:00 app[web.1]: Started GET "/users/sign_up" for 197.210.25.210 at 2016-10-26 17:46:19 +0000
2016-10-26T17:46:19.955368+00:00 app[web.1]: Processing by User::RegistrationsController#new as HTML
2016-10-26T17:46:19.957892+00:00 app[web.1]: Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms)
2016-10-26T17:46:19.958887+00:00 app[web.1]:
2016-10-26T17:46:19.958889+00:00 app[web.1]: NoMethodError (undefined method `for' for #<Devise::ParameterSanitizer:0x007f782dff6408>):
2016-10-26T17:46:19.958890+00:00 app[web.1]: app/controllers/user/registrations_controller.rb:7:in `configure_permitted_parameters'
2016-10-26T17:46:19.958891+00:00 app[web.1]:
2016-10-26T17:46:19.958892+00:00 app[web.1]:
2016-10-26T17:46:20.651597+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=johnuzoma-finance-tracker.herokuapp.com request_id=8d875ac1-de78-47 68-9cd0-a653afd2318b fwd="197.210.25.210" dyno=web.1 connect=0ms service=6ms status=304 bytes=133
RegistrationsController code
class User::RegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up).push(:first_name, :last_name)
devise_parameter_sanitizer.for(:account_update).push(:first_name, :last_name)
end
end
So the first thing you should do is go to the Heroku admin panel for your app and look through the log file. You should find a stack trace (should look like an error followed by a bunch of method calls and line numbers). Another option is for you to remotely access the app server, go to you Heroku app directory on your computer and run (assuming you have Heroku CLI installed)
heroku run bash
then navigate to your log directory and run
tail -f <replace_with_log_file_name>
(log file should be production.log or develop.log) and that will show you a real time stream of the log activity, so just go recreate the bug and see what happens.
Replace these lines
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up).push(:first_name, :last_name)
devise_parameter_sanitizer.for(:account_update).push(:first_name, :last_name)
end
With these lines
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name])
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name])
end
What happened is the gem devise that you are using changed its API in version for so the syntax you are were using is no longer valid. I am assuming that at some point in time you did a bundle update or something that inadvertently upgraded you gem
If you are facing this much difficulty in determining error through Heroku logs one more thing you can try is you can see error on the browser itself and to do that in your production.rb file (which you will find in config/environments directory) change:
config.action_controller.consider_all_requests_local = false
To:
config.action_controller.consider_all_requests_local = true
Now deploy your app again on Heroku and you are good to go.
Related
I am new to Ruby and Rails in general and am following this series
https://gorails.com/episodes/rails-for-beginners-part-38-deploying-to-heroku
I have this weird issue where is everything seems to work fine except connecting my app with
Twitter Api.
I did everything to connect successfully but nothing seems working!
I added the website link to Twitter developer callbacks urls which are
https://jadwlh.herokuapp.com/
along with
https://jadwlh.herokuapp.com/auth/twitter/callback
I added both
API_KEY
and
API_SECRET
to Config Vars.
I even changed SECRET_KEY_BASE in Config Vars
to the one provided in the credentials file in my app!
Even though tried everything, still got this message shown in the image below when I try to
connect my app with Twitter Api
routes.rb file
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
Rails.application.routes.draw do
#GET /about
get "about", to: "about#index"
get "password", to: "passwords#edit", as: :edit_password
patch "password", to: "passwords#update"
get "sign_up", to: "registrations#new"
post "sign_up", to: "registrations#create"
delete "logout", to: "sessions#destroy"
get "sign_in", to: "sessions#new"
post "sign_in", to: "sessions#create"
get "password/reset", to: "password_resets#new"
post "password/reset", to: "password_resets#create"
get "password/reset/edit", to: "password_resets#edit"
patch "password/reset/edit", to: "password_resets#update"
get "/auth/twitter/callback", to: "omniauth_callbacks#twitter"
resources :twitter_accounts
resources :tweets
# get "/", to: "main#index"
root to: "main#index"
end
Application logs
2021-05-31T06:15:04.415968+00:00 app[web.1]: [13f44544-8fd2-4348-8b08-1191ad53716b]
2021-05-31T06:15:04.418156+00:00 heroku[router]: at=info method=HEAD path="/auth/failure?message=session_expired&strategy=twitter" host=jadwlh.herokuapp.com request_id=13f44544-8fd2-4348-8b08-1191ad53716b fwd="217.182.175.162" dyno=web.1 connect=0ms service=3ms status=404 bytes=180 protocol=https
2021-05-31T06:15:31.243002+00:00 app[web.1]: I, [2021-05-31T06:15:31.242901 #4] INFO -- : [c5f8ff8c-58fa-439d-a9f3-e08047bc5aa8] Started POST "/auth/twitter" for 46.152.103.96 at 2021-05-31 06:15:31 +0000
2021-05-31T06:15:31.243645+00:00 app[web.1]: D, [2021-05-31T06:15:31.243583 #4] DEBUG -- omniauth: (twitter) Request phase initiated.
2021-05-31T06:15:31.388564+00:00 app[web.1]: E, [2021-05-31T06:15:31.388453 #4] ERROR -- omniauth: (twitter) Authentication failure! 400 Bad Request: OAuth::Unauthorized, 400 Bad Request
2021-05-31T06:15:31.390962+00:00 heroku[router]: at=info method=POST path="/auth/twitter" host=jadwlh.herokuapp.com request_id=c5f8ff8c-58fa-439d-a9f3-e08047bc5aa8 fwd="46.152.103.96" dyno=web.1 connect=1ms service=150ms status=302 bytes=834 protocol=https
2021-05-31T06:15:31.574904+00:00 heroku[router]: at=info method=GET path="/auth/failure?message=400+Bad+Request&strategy=twitter" host=jadwlh.herokuapp.com request_id=3adfd6f0-58b9-47c3-ab04-017161a56e18 fwd="46.152.103.96" dyno=web.1 connect=1ms service=6ms status=404 bytes=1902 protocol=https
2021-05-31T06:15:31.571195+00:00 app[web.1]: I, [2021-05-31T06:15:31.571067 #4] INFO -- : [3adfd6f0-58b9-47c3-ab04-017161a56e18] Started GET "/auth/failure?message=400+Bad+Request&strategy=twitter" for 46.152.103.96 at 2021-05-31 06:15:31 +0000
2021-05-31T06:15:31.572790+00:00 app[web.1]: F, [2021-05-31T06:15:31.572717 #4] FATAL -- : [3adfd6f0-58b9-47c3-ab04-017161a56e18]
2021-05-31T06:15:31.572791+00:00 app[web.1]: [3adfd6f0-58b9-47c3-ab04-017161a56e18] ActionController::RoutingError (No route matches [GET] "/auth/failure"):
2021-05-31T06:15:31.572792+00:00 app[web.1]: [3adfd6f0-58b9-47c3-ab04-017161a56e18]
Thank you: )
I found the solution.
It just was copying master.key and replace it as it says below!
heroku config:set RAILS_MASTER_KEY="copy and paste here config/master.key "
How to get rails master.key after upgrading to rails 5.2
Hi I'm fairly new to coding and I'm building a rails/react habit builder app. Everything works fine when running on local server. However I've switched the database over to postgres and deployed to heroku, and nearly everything works except for a create action in one of my of controllers.
def create
current_user.identities.build(identity_params)
if identity.save
render json: IdentitySerializer.new(identity).serialized_json
else
render json: { error: identity.errors.messages }, status: 422
end
end
here is my current_method
def current_user
#current_user ||= User.find(session[:user_id]) if session[:user_id]
end
here is the error in my heroku log
2020-11-16T16:14:03.944788+00:00 heroku[router]: at=info method=GET path="/api/v1/categories" host=atomic-habits-app.herokuapp.com request_id=94543abb-1522-464f-9c8e-44e7bc6f765b fwd="68.199.184.23" dyno=web.1 connect=1ms service=103ms status=304 bytes=445 protocol=https
2020-11-16T16:14:16.585828+00:00 app[web.1]: I, [2020-11-16T16:14:16.585700 #8] INFO -- : [f2c1ff5a-c6b8-4304-89a4-7174caed6c0b] Started POST "/api/v1/identities" for 68.199.184.23 at 2020-11-16 16:14:16 +0000
2020-11-16T16:14:16.587457+00:00 app[web.1]: I, [2020-11-16T16:14:16.587389 #8] INFO -- : [f2c1ff5a-c6b8-4304-89a4-7174caed6c0b] Processing by Api::V1::IdentitiesController#create as HTML
2020-11-16T16:14:16.587570+00:00 app[web.1]: I, [2020-11-16T16:14:16.587508 #8] INFO -- : [f2c1ff5a-c6b8-4304-89a4-7174caed6c0b] Parameters: {"identity"=>{"category_id"=>"1", "name"=>"test", "description"=>"test", "standard"=>"7"}}
2020-11-16T16:14:16.590058+00:00 app[web.1]: I, [2020-11-16T16:14:16.589975 #8] INFO -- : [f2c1ff5a-c6b8-4304-89a4-7174caed6c0b] Completed 500 Internal Server Error in 2ms (Allocations: 570)
2020-11-16T16:14:16.591415+00:00 app[web.1]: F, [2020-11-16T16:14:16.591334 #8] FATAL -- : [f2c1ff5a-c6b8-4304-89a4-7174caed6c0b]
2020-11-16T16:14:16.591416+00:00 app[web.1]: [f2c1ff5a-c6b8-4304-89a4-7174caed6c0b] NoMethodError (undefined method `identities' for nil:NilClass):
2020-11-16T16:14:16.591417+00:00 app[web.1]: [f2c1ff5a-c6b8-4304-89a4-7174caed6c0b]
2020-11-16T16:14:16.591417+00:00 app[web.1]: [f2c1ff5a-c6b8-4304-89a4-7174caed6c0b] app/controllers/api/v1/identities_controller.rb:17:in `create'
2020-11-16T16:14:16.592938+00:00 heroku[router]: at=info method=POST path="/api/v1/identities" host=atomic-habits-app.herokuapp.com request_id=f2c1ff5a-c6b8-4304-89a4-7174caed6c0b fwd="68.199.184.23" dyno=web.1 connect=0ms service=9ms status=500 bytes=1841 protocol=https
And again, this create action works perfectly fine when I run it on my local server. And in production the create method works for signing up a user and creating a session. And when creating a session I console.log the response from the sessions controller which includes
render json: {
logged_in: true,
current: current_user,
user: #user
}
And the current user object gets logged to the console upon login.
So im not sure if the issue is relationship related between identity and users (user has many identities), or if there is an issue relying on sessions in production? I've really made no progress debugging this. Any ideas or advice is very much appreciated. Sorry if I left out any necessary code. Here are links to repo and heroku
https://atomic-habits-app.herokuapp.com/
https://github.com/mattkuras/Habit-Helper
edit**
Thank you Eyeslandic for this response it seems to be working.
"Rails.application.config.session_store :cookie_store, key: '_habit-helper', domain: 'localhost:3000' could be the problem, referencing port 3000 especially"
I changed port 3000 to :all in my config/initializers/session_store.rb. The cookie wasnt properly being set
So I have a rails 3.2 app. I created an index.
I followed this guide: https://gist.github.com/nz/2041121 to create an bonsai.rb file in config/initializers/bonsai.rb
It looks like this:
ENV['ELASTICSEARCH_URL'] = ENV['BONSAI_URL']
# Optional, but recommended: use a single index per application per environment.
# Caveat: This convention not be entirely supported throughout Tire's API.
app_name = Rails.application.class.parent_name.underscore.dasherize
app_env = Rails.env
INDEX_NAME = "#{app_name}-#{app_env}"
But I dosent work, this outprint from the heroku logs:
2013-03-06T17:04:54+00:00 app[web.1]: Processing by SchoolsController#index as HTML
2013-03-06T17:04:54+00:00 app[web.1]: Started GET "/trafikskola?utf8=%E2%9C%93&query=Malm%C3%B6" for 192.165.96.102 at 2013-03-06 17:04:54 +0000
2013-03-06T17:04:54+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "query"=>"Malmö"}
2013-03-06T17:04:58+00:00 heroku[router]: at=info method=GET path=/trafikskola?utf8=%E2%9C%93&query=Malm%C3%B6 host=stormy-escarpment-2346.herokuapp.com fwd="192.165.96.102" dyno=web.1 queue=0 wait=0ms connect=1ms service=3106ms status=500 bytes=643
2013-03-06T17:04:58+00:00 app[web.1]:
2013-03-06T17:04:58+00:00 app[web.1]: app/models/school.rb:19:in `search'
2013-03-06T17:04:58+00:00 app[web.1]: app/controllers/schools_controller.rb:10:in `index'
2013-03-06T17:04:58+00:00 app[web.1]: Completed 500 Internal Server Error in 3073ms
2013-03-06T17:04:58+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2013-03-06T17:04:58+00:00 app[web.1]:
2013-03-06T17:04:58+00:00 app[web.1]:
My questions:
Should I put somehting in the ELASTICSEARCH_URL in the bonsai.rb file? If yes, then what?
I have created a local index to, does that mean something?
Or is it something else?
The config/initializers/bonsai.rb was right and the problem was I had to index it in production mode also.
So I did this:
heroku rake environment tire:import CLASS=School FORCE=true
And it worked.
I'm making a simple blog to learn rails.
Everything is almost finished, and I'm trying to apply HTTP authentication, as outlined here --> http://berk.es/2011/03/29/simplest-authentication-in-rails-basic-authentication-with-a-logged_in-helper/
My authentication code looks like this, in the ApplicationController
class ApplicationController < ActionController::Base
protect_from_forgery
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == ADMIN_ID && password == ADMIN_PASSWORD
end
end
end
instead of passing the variable in my files, however, I want to pass it through heroku. So I ran -->
heroku config:add ADMIN_ID=myusername
heroku config:add ADMIN_PASSWORD=mypassword
When I tried logging in though I get a "Something went wrong" message. Here's what heroku logs say :
GET fast-chamber-1998.herokuapp.com/admin dyno=web.1 queue=0 wait=0ms service=10ms status=500 bytes=643
2012-11-11T07:18:47+00:00 app[web.1]:
2012-11-11T07:18:47+00:00 app[web.1]:
2012-11-11T07:18:47+00:00 app[web.1]: Started GET "/admin" for 60.245.65.132 at 2012-11-11 07:18:47 +0000
2012-11-11T07:18:47+00:00 app[web.1]: Processing by PostsController#admin as HTML
2012-11-11T07:18:47+00:00 app[web.1]: Completed 500 Internal Server Error in 1ms
2012-11-11T07:18:47+00:00 app[web.1]:
2012-11-11T07:18:47+00:00 app[web.1]: NameError (uninitialized constant ApplicationController::ADMIN_ID):
2012-11-11T07:18:47+00:00 app[web.1]: app/controllers/application_controller.rb:7:in `block in authenticate'
2012-11-11T07:18:47+00:00 app[web.1]: app/controllers/application_controller.rb:6:in `authenticate'
2012-11-11T07:18:47+00:00 app[web.1]:
2012-11-11T07:18:47+00:00 app[web.1]:
From the looks of it, I think the environment variables I passed don't seem to be detected. What do you suggest I do?
You should access them as ENV['ADMIN_ID'] and ENV['ADMIN_PASSWORD']
I have a form in my app which is triggering the wrong controller action. Here's the rendered form:
<form id="edit_profile_1" class="simple_form profile windowed" method="post" enctype="multipart/form-data" action="/profiles/1" accept-charset="UTF-8">
<div style="margin:0;padding:0;display:inline">
<input type="hidden" value="✓" name="utf8">
<input type="hidden" value="put" name="_method">
<input type="hidden" value="..." name="authenticity_token">
</div>
....
</form>
So, pretty much a normal form. On my local environment this works fine, it triggers the profiles#update action. However, when deployed on Heroku for some reason this is triggering the profiles#show action, and therefore is not working.
What gives? Has anyone encountered this error before, and do you know how to fix it?
-EDIT- #Laas: Here's the production log:
2011-05-20T21:41:38+00:00 app[web.1]: Started GET "/account" for 98.201.59.6 at 2011-05-20 14:41:38 -0700
2011-05-20T21:41:40+00:00 heroku[router]: GET www.fourthenvironment.org/account dyno=web.1 queue=0 wait=0ms service=2212ms bytes=8672
2011-05-20T21:41:40+00:00 app[web.1]: Connected to NewRelic Service at collector-6.newrelic.com:80
2011-05-20T21:41:40+00:00 heroku[router]: GET www.fourthenvironment.org/javascripts/rails.js dyno=web.1 queue=0 wait=0ms service=2ms bytes=5176
2011-05-20T21:41:41+00:00 heroku[router]: GET www.fourthenvironment.org/javascripts/jquery.144.min.js dyno=web.1 queue=0 wait=0ms service=3ms bytes=78865
2011-05-20T21:41:42+00:00 heroku[router]: GET www.fourthenvironment.org/stylesheets/style.css dyno=web.1 queue=0 wait=0ms service=3ms bytes=63444
2011-05-20T21:41:47+00:00 heroku[router]: GET www.fourthenvironment.org/favicon.ico dyno=web.1 queue=0 wait=0ms service=4ms bytes=1672
2011-05-20T21:41:50+00:00 app[web.1]:
2011-05-20T21:41:50+00:00 app[web.1]:
2011-05-20T21:41:50+00:00 app[web.1]: Started POST "/profiles/1" for 98.201.59.6 at 2011-05-20 14:41:50 -0700
2011-05-20T21:41:50+00:00 heroku[router]: POST www.fourthenvironment.org/profiles/1 dyno=web.1 queue=0 wait=0ms service=102ms bytes=420
2011-05-20T21:41:50+00:00 app[web.1]: THIS SHOULD NOT BE TRIGGERED
2011-05-20T21:41:50+00:00 heroku[router]: GET www.fourthenvironment.org/profiles/1 dyno=web.1 queue=0 wait=0ms service=30ms bytes=414
2011-05-20T21:41:50+00:00 app[web.1]:
2011-05-20T21:41:50+00:00 app[web.1]:
2011-05-20T21:41:50+00:00 app[web.1]: Started GET "/account" for 98.201.59.6 at 2011-05-20 14:41:50 -0700
Note the "THIS SHOULD NOT BE TRIGGERED". Here's the controller:
class ProfilesController < ApplicationController
before_filter :authenticate_user!
def show
puts "THIS SHOULD NOT BE TRIGGERED"
redirect_to account_path
end
def edit
#profile = Profile.find(params[:id])
end
def update
puts "profiles#update"
#profile = Profile.find(params[:id])
if #profile.update_attributes(params[:profile])
redirect_to account_path, :notice => t('user.notice.updated')
else
render :action => 'edit'
end
end
end
It turns out the issue was related to the use of the SSL-Requirement Gem. For some reason if you send a request from an SSL page to a non-SSL page while using SSL-requirement it gets redirected. So, to fix, enable SSL-requirement on both ends of the request, and it will work. It looks like going from SSL to non SSL the gem only allows gets -- hence the bug. This looks to be irrelevant as of Rails 3.1 since a new SSL requirement functionality will be baked-in and the gem will not be required.
Many thanks to the Heroku staff for helping isolate this.
Seems to be identical to this problem routing-issues-with-multi-part-forms-on-heroku.
As it is only few days old, maybe it is not a coincidence and there's something awry with Heroku?
Why is the form tag hard coded? Use the form_tag helper
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html