Hey so I am following the One Month Rails guide to learning Ruby and I have hit a wall on one of the lessons. I have just finished uploading an image with Paperclip, and as I finished my work on my localhost and checked it on Heroku, something went wrong. The pin/image appears to have been pushed to my Heroku account, the only problem is that the username and password that works for my localhost:3000 won't work for my Heroku account. The same password should work for both, but for some reason something is wrong. I wish I could give you the action that is going on in my terminal, but the ruby rails is the only thing that has a continuous status flow. The problem may have been when I switched my password after not using my account on localhost for a few weeks, but i thought that once i "git pushed" that to heroku master, it would've synced. I have tried heroku run rake db:setup which didn't seem to do too much as well as wrestled by way through "Importing a Heroku Postgres Database with PG Backups", but I had some trouble working through that. Any ideas? Thanks for the help.
Your 'database.yml' should not be sent to Heroku, they take care of that, creating a new database.yml config file with the proper DB access details.
Try logging into your Heroku instance and deleting the file.
Edit: nevermind, assumed you were not able to connect to the DB, not to login into the website.
So if I'm understanding you correctly, you've deployed your application to Heroku and the login (to your application) that was working locally doesn't work on Heroku.
Deploying your application doesn't deploy data. Assuming you've run heroku run rake db:migrate then your database schemas will at least match.
At this point, you've got a couple of options.
Use a seeds.rb file which you can load with heroku run db:seed to setup some 'seed' data so that you can login.
Push your local database to Heroku - either via heroku db:push or using heroku pg:transfer provided by https://github.com/ddollar/heroku-pg-transfer
Use heroku run console to create your user account via the command line
User.create(email: 'someemail.com', password: 'somepassword', password_confirmation: 'somepassword')
I'd be inclined to go with the later option.
How did the user get in their in the first place? Perhaps going back to that step in the tutorial - just remember, if you are using rails console locally to use heroku run console on Heroku.
Related
First time posting a question.
I recently did a Rails project on Udemy and it works fine on localhost, when I pushed to Heroku I only see signup/login page, none of the 'New,Edit,Delete..' pages. Installed pg and rails_12factor in production, and sqlite in test and dev. The teacher hasn't answered on the forum in a week so looking in other places. Here's my GitHub link https://github.com/guruprasadnagarajan/taskr and this is the Heroic page https://taskr-guru.herokuapp.com
Thanks!
When you create a heroku app and after you've created the database, you need to also migrate and add data to the database. Make sure that you have valid users and other needed data. For example, you can access the rails console of your application by running:
heroku run rails c -a <your app's name>
Then you can create users from there using rails models like:
User.create(name: <a name>, email: <an email>)
Alternatively you may create the needed data in the db/seed.rb file and then just run the task:
heroku run rake db:seed -a <your app's name>
If you have done all these steps above and still have the same issue, I am not sure how to go around it.
Hope it helps, happy coding!
I recently deployed a RoR app to Heroku.
The app loads fine.
I have a 'new' action that creates a new model record via a form submission (POST).
The issue is:
On submit, the controller writes to my local database and redirects to my local view corresponding to the controller action: http://localhost:3000/mycontroller/myview
My production database is empty! Any ideas on what is causing this and the fix?? Why is my remote deployment on Heroku accessing localhost???
I only need production on Heroku.
advTHANXance!
Have you tried
RAILS_ENV=production rails db:create
RAILS_ENV=production rails db:migrate
But if you don't run those two, you will surely get migrate error.
Please provide some details about your error.
1) Check if you have a postgres plugin in heroku console
2) Secondly when you push check if you get any error related to PG .
3) dont forget to do heroku restart --app appname
4) login to heroku using **heroku bash** and then run rails c, then check that what database you are using
for it use the command
ActiveRecord::Base.connection_config
now you will get response like
{:adapter=>ADAPTER_NAME, :host=>HOST, :port=>PORT,
:database=>DB, :pool=>POOL, :username=>USERNAME,
:password=>PASSWORD}
if you see dbname as the name in heroku dashboard database name
if it is same then the database is what you are using is of production.
and for transfer to local,re-check your routes and clear your cache,thats the only reason for it.
My app runs properly locally and has a crash when it runs on Heroku. The app does fine until I run a new_post_path call. I tried git push to see if a change to the new.html.erb file or the _form.html.erb file was the issue - but I think during the last push to heroku - my database may have taken a hit. At the time I was adding a t.text field (longtext) and it seems to be the issue.
So I wanted to roll back or totally re-start at heroku. But I have not found anyway to do it. Since this is not near production yet. Is there anyway to just create a new instance at heroku and push up to it?
Again, local version runs perfect. Thanks in advance for any ideas.
I would say there are several ways to handle this problem
restarting heroku
Run $ heroku restart in the rails dir. Sometimes I believe in magic.
debugging
Use $ heroku log to debug what is causing the error.
migrate database
Perhaps you made a database change in local rails, while heroku rails didn't.
Run heroku run rake db:migrate
drop database and remigrate database
See this thread. Sometimes old migration might be in conflict with current migration. Do a clean migration, if the data in your database isn't important.
recreate heroku instance
run $ heroku apps:destroy –app appname and replace appname with your appname. Then delete the current heroku remote repository location from git. git remote rm heroku. Then recreate heroku. run $ heroku create. go through pushing your code and migrating database like usual.
Relaunching might be the least of your problems, so I suggest a few things:
Review this Heroku article on releases, including the Heroku rollback feature.
Add the PG Backups add-on to your app.
I also recommend using something like the exception_notification gem in combination with the SendGrid add-on, so that you can get an email with details on the error as well.
I've succesfully submitted my app to git, and then pushed it to heroku. Starting page working as it has to, but the rest with path heroku_site.com/pages/page_name says me "We're sorry, but something went wrong." Same pages works fine on local server.
Any ideas whats wrong?
inb4 routes are fine(and rest too, rspec spec/ green)
You can view your Heroku logs with $ heroku logs
Looking at your routs, I'd guess that your page is based on content in your local database that you have not added yet to your production database.
If so, you can either push your local database to production $ heroku db:push
Or you can put that data in a Rails migration or seed it. Or you can go create it in your production app.
In general, to find out what you can do: $ heroku help
I've been having problems yesterday with Heroku shared Postgres DB. It looks like my db is not correctly 'pushed' to my heroku DB.
Configuration
Using 'pg' gem for both development and production environments.
Using Heroku's 'shared-database' add-on.
Running Rails 3.1.1.
What I'm trying to do
Push my source code to Heroku and then synchronize my postgres DB with Heroku's one. No problem for the source itself, but I can't get my DB up and running.
What I've tried so far
1: Source code push : git push heroku master. OK. This works.
2: Then I try to run : heroku db:push. Seems to be running normally, no error, the schema is sent to Heroku, the different tables are correctly detected and seem to be sent as well :
3: Let's check it out, is everything allright ? heroku info :
Doh ! The database is still empty (and therefore I get DB-related errors when accessing dynamic pages). Can't understand what's happening, I've spent time on this issue yesterday evening but only been mpessing with Heroku for a little while and never encountered this issue. Any clues ?
I'm not convinced that the Database size figure is a live figure. Here's a clean deployment of an app to Heroku and the output of heroku info at each stage. The first run is post application creation, the second after a push of the code, the third after a heroku db:push.
The database was uploaded before the third output and the application is running however the DB:size is not reporting the figure.
Is your application actually erroring because the database isn't present?
The problem is in the commit process.
You should run manually after each commit from your console :
heroku run rake db:migrate
Enjoy
daniel