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.
Related
I have deployed my app to heroku but and I can see the app but the app is NOT accessing the mongolab database. I have tried resetting the database in console with
$ heroku run rake db:reset
but I get this error.
failed with error 13: "not authorized on ENV['MONGOID_DATABASE'] to execute command { dropDatabase: 1 }"
See https://github.com/mongodb/mongo/blob/master/docs/errors.md
Not sure what I am doing wrong, I have not setup an app with mongoid on heroku before, this is my first time
-UPDATE-
Here is the end of the log I have that seems to show the post is not working.
$ heroku logs
2015-09-25T16:20:15.770927+00:00 heroku[router]: at=info method=POST path="/managers" host=beta.herokuapp.com request_id=95709038-02e9-45b1-8300-0aebc287f6c1 fwd="162.239.42.196" dyno=web.1 connect=0ms service=178ms status=500 bytes=1480
2015-09-25T16:20:15.770408+00:00 app[web.1]: D, [2015-09-25T16:20:15.770342 #3] DEBUG -- : MOPED: 10.152.165.9:29821 QUERY database=ENV['MONGOID_DATABASE'] collection=managers selector={"email"=>"sample#email.com"} flags=[] limit=-1 skip=0 batch_size=nil fields={:_id=>1} runtime: 1.0352ms
Here are the router logs...
$ heroku logs --ps router
2015-09-25T20:40:46.935184+00:00 heroku[router]: at=info method=POST path="/managers" host=beta.herokuapp.com request_id=c1673463-a69f-4111-bd4d-01fdb5516ad0 fwd="162.239.42.196" dyno=web.1 connect=2ms service=109ms status=500 bytes=1480
2015-09-25T20:40:47.285029+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=beta.herokuapp.com request_id=1e998283-b02b-4cc5-83f6-7996a6991531 fwd="162.239.42.196" dyno=web.1 connect=1ms service=2ms status=200 bytes=143
2015-09-26T04:45:32.833599+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=beta.herokuapp.com request_id=59ccc2e7-18d4-4c08-8b08-a653f5d11714 fwd="2602:30a:2ef2:ac40:acb1:9144:79b4:affb,66.249.88.51" dyno=web.1 connect=1ms service=4ms status=200 bytes=143
I also see it failing to query the database
2015-09-26T05:03:39.852170+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"WVGY+XLD...A=", "manager"=>{"name"=>"Blah Blah", "company"=>"Blah Blah CO.", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
2015-09-26T05:03:40.138442+00:00 app[web.1]: D, [2015-09-26T05:03:40.138321 #3] DEBUG -- : MOPED: 10.152.165.9:29821 COMMAND database=admin command={:ismaster=>1} runtime: 23.5306ms
2015-09-26T05:03:40.146776+00:00 app[web.1]: Completed 500 Internal Server Error in 294ms
2015-09-26T05:03:40.146782+00:00 app[web.1]: Completed 500 Internal Server Error in 294ms
2015-09-26T05:03:40.152205+00:00 app[web.1]:
2015-09-26T05:03:40.152208+00:00 app[web.1]: Moped::Errors::QueryFailure (The operation: #<Moped::Protocol::Query
2015-09-26T05:03:40.152209+00:00 app[web.1]: #length=112
2015-09-26T05:03:40.152211+00:00 app[web.1]: #request_id=4
2015-09-26T05:03:40.152212+00:00 app[web.1]: #response_to=0
2015-09-26T05:03:40.152214+00:00 app[web.1]: #op_code=2004
2015-09-26T05:03:40.152215+00:00 app[web.1]: #flags=[]
2015-09-26T05:03:40.152216+00:00 app[web.1]: #full_collection_name="ENV['MONGOID_DATABASE'].managers"
2015-09-26T05:03:40.152218+00:00 app[web.1]: #skip=0
2015-09-26T05:03:40.152219+00:00 app[web.1]: #limit=-1
2015-09-26T05:03:40.152222+00:00 app[web.1]: #selector={"email"=>"sample#email.com"}
2015-09-26T05:03:40.152224+00:00 app[web.1]: #fields={:_id=>1}>
2015-09-26T05:03:40.152225+00:00 app[web.1]: failed with error 13: "not authorized for query on ENV['MONGOID_DATABASE'].managers"
2015-09-26T05:03:40.152227+00:00 app[web.1]:
2015-09-26T05:03:40.152228+00:00 app[web.1]: See https://github.com/mongodb/mongo/blob/master/docs/errors.md
I figured it out. The db was not connecting because the mongoid.yml file was incorrect. I tweaked the yml file and added the URI to the heroku variables and it worked correctly.
Hi i was pushing my code to heroku and i got "internal server error", along with a message "You must set config.secret_key_base in your app's config."
attached is my heroku logs:
2014-08-24T09:59:08.327640+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=morning-shore-7679.herokuapp.com request_id=
41ececcc-6a0d-4af1-832c-c0123335836a fwd="10.168.82.110 ,220.255.1.160" dyno=web.1 connect=1ms service=6ms status=500 bytes=562
2014-08-24T09:59:08.326020+00:00 app[web.1]: [2014-08-24 09:59:08] ERROR RuntimeError: You must set config.secret_key_base in your app's
config.
2014-08-24T09:59:08.326025+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.8/lib/rails/application.rb:145:in `env_co
nfig'
2014-08-24T09:59:08.326027+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.8/lib/rails/engine.rb:507:in `call'
2014-08-24T09:59:08.326028+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.8/lib/rails/application.rb:97:in `call'
2014-08-24T09:59:08.326032+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2014-08-24T09:59:08.326030+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2014-08-24T09:59:08.326034+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-08-24T09:59:08.326035+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2014-08-24T09:59:08.326038+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2014-08-24T09:59:08.326037+00:00 app[web.1]: /app/vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
Can anyone shed some light on this?
I think the easiest way to get ride of this issue is to generate secrets and push into your git repo.
# on terminal from project root
rake secret
Put this generated secret in config/initializers/secret_token.rb file:
# Be sure to restart your server when you modify this file.
Yourapp::Application.config.secret_token = 'YOUR_GENERATED_SECRET'
Commit & push code to heroku.
I don't know where else to turn with this: I have spent many hours on my project, a recruiting events website for college students, but have reached quite the impasse.
In short, I plodded along in localhost - adding components like Devise; Omniauth authentication via providers Facebook, LinkedIn, and Google - building a website I was proud of along the way. Everything appeared to be working just fine, but once I pushed to 'heroku master' things started breaking big time.
I think the issues are most likely in or around:I have an Authentication model to keep track of a single user's authentication providers, alongside the User model (where all the oauth code is kept).
Without further ado, here is my app's heroku domain and my code:
http://lit-everglades-7633.herokuapp.com/
https://gist.github.com/mecampbellsoup/6357855
The things breaking which I suspect are related:
'heroku run rake db:seed' following 'pg:reset' & 'rake db:migrate'... instead of seeding with the contents of the seed file itself, a single blank Event and Company are created; more on this below
the routing and action relating to the omniauth request seems to be working just fine, according to the heroku logs (below) but no user nor authentication is actually created:
when, after resetting postgres db, I try to run 'heroku run rake db:create' or 'db:setup' I am whined at as follows:
☁ duke_recruits [master] heroku run rake db:setup
Running rake db:setup attached to terminal... up, run.5886
FATAL: permission denied for database "postgres"
DETAIL: User does not have CONNECT privilege.
also, 'heroku run rake db:seed' appears to be doing its thing, but then my db only has 1 empty Event and 1 empty Company:
☁ duke_recruits [master] heroku run rake db:seed
Running rake db:seed attached to terminal... up, run.1767
☁ duke_recruits [master] heroku run rails c
Running rails c attached to terminal... up, run.6135
Event.allLoading production environment (Rails 4.0.0)
irb(main):001:0> Event.all
=> #ActiveRecord::Relation [#Event id: 1, title: nil, location: nil, description: nil, date: nil, end_date: nil, company_id: nil, created_at: "2013-08-27 19:30:06", updated_at: "2013-08-27 19:30:06"]
irb(main):002:0> Company.all
=> #ActiveRecord::Relation [#Company id: 1, name: nil, description: nil, website: nil, logo: nil, created_at: "2013-08-27 19:30:06", updated_at: "2013-08-27 19:30:06"]
Logs (upon opening the app on heroku and trying google authentication):
2013-08-27T19:49:18.701285+00:00 app[web.1]: Started GET "/" for 68.175.76.48 at 2013-08-27 19:49:18 +0000
2013-08-27T19:49:18.701019+00:00 app[web.1]: => Rails 4.0.0 application starting in production on http://0.0.0.0:49710
2013-08-27T19:49:18.701019+00:00 app[web.1]: => Ctrl-C to shutdown server
2013-08-27T19:49:18.701019+00:00 app[web.1]: => Booting WEBrick
2013-08-27T19:49:18.701019+00:00 app[web.1]: => Run `rails server -h` for more startup options
2013-08-27T19:49:18.701019+00:00 app[web.1]: Started GET "/" for 68.175.76.48 at 2013-08-27 19:49:18 +0000
2013-08-27T19:49:19.131115+00:00 heroku[router]: at=info method=GET path=/ host=lit-everglades-7633.herokuapp.com fwd="68.175.76.48" dyno=web.1 connect=2ms service=442ms status=304 bytes=0
2013-08-27T19:49:19.221284+00:00 heroku[router]: at=info method=GET path=/assets/application-b44a43097f814ac98347f6802323e25f.js host=lit-everglades-7633.herokuapp.com fwd="68.175.76.48" dyno=web.1 connect=1ms service=12ms status=304 bytes=0
2013-08-27T19:49:49.440894+00:00 app[web.1]: Started GET "/" for 68.175.76.48 at 2013-08-27 19:49:49 +0000
2013-08-27T19:49:49.440894+00:00 app[web.1]: Started GET "/" for 68.175.76.48 at 2013-08-27 19:49:49 +0000
2013-08-27T19:49:49.515520+00:00 heroku[router]: at=info method=GET path=/ host=lit-everglades-7633.herokuapp.com fwd="68.175.76.48" dyno=web.1 connect=2ms service=80ms status=304 bytes=0
2013-08-27T19:50:48.534099+00:00 app[web.1]: Started GET "/" for 68.175.76.48 at 2013-08-27 19:50:48 +0000
2013-08-27T19:50:48.534099+00:00 app[web.1]: Started GET "/" for 68.175.76.48 at 2013-08-27 19:50:48 +0000
2013-08-27T19:50:48.575279+00:00 heroku[router]: at=info method=GET path=/ host=lit-everglades-7633.herokuapp.com fwd="68.175.76.48" dyno=web.1 connect=1ms service=51ms status=304 bytes=0
2013-08-27T19:50:52.293922+00:00 app[web.1]: Started GET "/users/sign_up" for 68.175.76.48 at 2013-08-27 19:50:52 +0000
2013-08-27T19:50:52.293922+00:00 app[web.1]: Started GET "/users/sign_up" for 68.175.76.48 at 2013-08-27 19:50:52 +0000
2013-08-27T19:50:52.591752+00:00 heroku[router]: at=info method=GET path=/users/sign_up host=lit-everglades-7633.herokuapp.com fwd="68.175.76.48" dyno=web.1 connect=1ms service=307ms status=304 bytes=0
2013-08-27T19:51:00.368352+00:00 app[web.1]: Started GET "/users/auth/google_oauth2" for 68.175.76.48 at 2013-08-27 19:51:00 +0000
2013-08-27T19:51:00.368352+00:00 app[web.1]: Started GET "/users/auth/google_oauth2" for 68.175.76.48 at 2013-08-27 19:51:00 +0000
2013-08-27T19:51:00.368926+00:00 app[web.1]: I, [2013-08-27T19:51:00.368823 #2] INFO -- omniauth: (google_oauth2) Request phase initiated.
2013-08-27T19:51:00.392262+00:00 heroku[router]: at=info method=GET path=/users/auth/google_oauth2 host=lit-everglades-7633.herokuapp.com fwd="68.175.76.48" dyno=web.1 connect=3ms service=33ms status=302 bytes=469
2013-08-27T19:51:00.715597+00:00 app[web.1]: Started GET "/users/auth/google_oauth2" for 68.175.76.48 at 2013-08-27 19:51:00 +0000
2013-08-27T19:51:00.715597+00:00 app[web.1]: Started GET "/users/auth/google_oauth2" for 68.175.76.48 at 2013-08-27 19:51:00 +0000
2013-08-27T19:51:00.716822+00:00 app[web.1]: I, [2013-08-27T19:51:00.716706 #2] INFO -- omniauth: (google_oauth2) Request phase initiated.
2013-08-27T19:51:00.997866+00:00 app[web.1]: Started GET "/users/auth/google_oauth2/callback?state=40ecfd10739cb874b5c461fc00cfd72ec4fcb694ef3a6878&code=4/D_(omitted_for_security)_GBlmiYhY(partially_omitted)E9yth.QpxI3jdcGpYYshQV0ieZDAoQOqyCgQI" for 68.175.76.48 at 2013-08-27 19:51:00 +0000
2013-08-27T19:51:00.997866+00:00 app[web.1]: Started GET "/users/auth/google_oauth2/callback?state=10739cb874b5c461fc00cfd72ec4fcb694ef3a6878&code=4/D_GBlmiYhY1rCvgdgE9yth.QpxI3jdcGpYYshQV0ieZDAoQOqyCgQI" for 68.175.76.48 at 2013-08-27 19:51:00 +0000
2013-08-27T19:51:00.998508+00:00 app[web.1]: I, [2013-08-27T19:51:00.998379 #2] INFO -- omniauth: (google_oauth2) Callback phase initiated.
2013-08-27T19:51:02.188467+00:00 app[web.1]: Started GET "/users/sign_up" for 68.175.76.48 at 2013-08-27 19:51:02 +0000
2013-08-27T19:51:02.188467+00:00 app[web.1]: Started GET "/users/sign_up" for 68.175.76.48 at 2013-08-27 19:51:02 +0000
2013-08-27T19:51:02.234644+00:00 heroku[router]: at=info method=GET path=/users/sign_up host=lit-everglades-7633.herokuapp.com fwd="68.175.76.48" dyno=web.1 connect=9ms service=52ms status=304 bytes=0
Please let me know what questions you have for me and if I can clarify anything at all. I really appreciate your time & help SO!
After a pg:reset, you can run the create command, but it usually gives you output like:
slkdjfs0dslkd already exists
So then you'll know that your database is created and ready to be used. Before you can seed though make sure you migrate. Just the standard heroku way
heroku run rake db:migrate
Then seed as normal
heroku run rake db:seed
I have just deployed my app on Heroku. I have access to home however when I create an account I have the error "we're sorry but something were wrong". In the heroku console there are the following lines :
2013-07-25T14:43:57.205734+00:00 app[web.1]:
2013-07-25T14:43:57.326077+00:00 app[web.1]:
2013-07-25T14:43:57.326077+00:00 app[web.1]: app/controllers/users_controller.rb:36:in `create'
2013-07-25T14:43:57.326077+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - {:data=>"<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">User 23</field><field name=\"type\">User</field><field name=\"type\">ActiveRecord::Base</field><field name=\"class_name\">User</field><field name=\"nom_text\">julien</field><field name=\"email_text\">julien#resenders.com</field></doc></add>", :headers=>{"Content-Type"=>"text/xml"}, :method=>:post, :params=>{:wt=>:ruby}, :query=>"wt=ruby", :path=>"update", :uri=>#<URI::HTTP:0x007f987b4c48a0 URL:http://localhost:8080/solr/update?wt=ruby>, :open_timeout=>nil, :read_timeout=>nil, :retry_503=>nil, :retry_after_limit=>nil}):
2013-07-25T14:43:57.337273+00:00 app[web.1]: Processing by UsersController#create as HTML
2013-07-25T14:43:57.326077+00:00 app[web.1]:
2013-07-25T14:43:57.326077+00:00 app[web.1]:
2013-07-25T14:43:57.337273+00:00 app[web.1]: Completed 500 Internal Server Error in 850ms
2013-07-25T14:43:57.337273+00:00 app[web.1]: Parameters: {"utf8"=>"???", "authenticity_token"=>"gdLt0F1TJi+GaFCe8sFFKRikXgAEEnW6DmIyPbLeCa4=", "user"=>{"nom"=>"julien", "email"=>"julien#resenders.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "resender"=>"0", "gang_id"=>"1", "addresses_attributes"=>{"0"=>{"first_name"=>"L", "last_name"=>"L"}}}, "commit"=>"Inscription"}
2013-07-25T14:43:57.337273+00:00 app[web.1]: Rendered devise/mailer/confirmation_instructions.html.erb (1.3ms)
2013-07-25T14:43:57.344954+00:00 heroku[router]: at=info method=POST path=/users host=www.resenders.com fwd="37.58.138.20" dyno=web.1 connect=4ms service=930ms status=500 bytes=643
I figured out the problem in local with "rake sunspot:solr:run" but even if "heroku run rake sunspot:solr:run" seems to work, it does not sort out this trouble on Heroku. How can I do ? Maybe with Websolr ? Thank you in advance guys !
4 Suggestions:
Be sure that your server is running
Be sure that your routes are set correctly
Add the websolr add on to your heroku stack --> https://devcenter.heroku.com/articles/websolr
Be sure to always remove personal data when pasting code to the internet
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']