Ruby on Rails / Heroku where are my users emails stored - ruby-on-rails

I am new to Ruby on Rails and Heroku. I have installed the gem 'Devise' in my RoR app and I use Heroku to deploy my app. The sign up process works fine but where are my users emails stored (the users that sign up for my website)? I want to be able to see/extract a list of all the emails.

You can view your users and any other database records by running:
heroku run rails console
from a terminal window. And from there you can run any rails console command as you can on your local machine like User.all

One thing I have found useful is to use either the config variables or the Postgres dashboard to get the URL information for the database. I then use that information to construct the JDBC URL for my IDE, RubyMine, to connect to Heroku. As a result, I can view and manipulate the data in all my tables on Heroku from my IDE. You can do something similar for the SQL tool of your choice.

Related

Merging changes made to users in the Heroku production web app with my local development database

When I log onto the website (example.herokuapp.com) and create a user, the user is created in the Heroku Postgres::Database but when I go into Cloud9 and enter Rails Console, the user does not exist in my production database. How can I merge the changes made in production (Heroku) with development (local Rails) so that these users show up in Rails Console? Thanks.
If you need the users to show up in the console you can run
heroku run console --app APP_NAME
If you'd like to "merge" the database you have to export your heroku Postgres database and convert the table to SQL format.
For more information about exporting PG Backups: https://devcenter.heroku.com/articles/heroku-postgres-import-export
Another stackoverflow post that might help: How to I merge two databases with same schema that are on Heroku?

Error while typing rails server command

I am a beginner.I am trying to launch rails server using the command.But I am getting an error. I tried searching in the google but no results.I will attach a picture of the log I got when I executed that command.
What Mysql error are you getting?
And what is in your config/database.yml?
So far, you have created the folder structure for a Rails app (rails new), then installed all the relevant components (bundle install).
When you start the server (rails server) it starts in "development" mode (you also have "test" mode for unit tests and "production" mode for when your app is live - and each has slightly different options). One of the first things the Rails server tries to do is connect to the database, so it looks in config/database.yml for the database specified in the development section.
So probably, it's trying to connect to a database that doesn't exist yet, with a username and password that are wrong.
First thing to do is to update the username and password in config/database.yml to match your local Mysql server.
Second thing to do is to build the development database; the command for that is "bin/rake db:create" (or "bundle exec rake db:create" if you're on Rails 3.x).
Hopefully that should be enough to get your server started.
How did you setup your rails app?
It seems like maybe you didn't type
bundle install
This command downloads and updates all of your gems. Action View is a rails dependency.

Is there a way to log commands from Rails console in Heroku?

Hi I am using Heroku and Ruby on Rails. In heroku I can do
heroku run rails c -a app
Which gives me console access, and I can do administrative things like deleting records
I am working in a company setting and I would like to have a log of all commands entered in the console. So if something is wrong, we can audit the logs.
Is there a way to record what is typed in the rails console?
Rails allows you to store the console history but this won't be saved in Heroku, at least not permanently.
In Heroku, when you run heroku run rails console Heroku will create a one-off dyno which will only live as long as the console session. Rails will store the history of commands on the filesystem but once the console is exited the dyno will be cleaned up and the command history file will be deleted along with it.
Rails console is a Railtie and it has some lifecycle hooks, so you could come up with some custom way to persist commands, but there is no built-in way to do it.
Yes, you can now using Heroku's shield private spaces, https://elements.heroku.com/addons/heroku-private-spaces.

Syncing Heroku and localhost databases

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.

How do I check the records of my heroku database?

I've just deployed my application to heroku and pointed my custom domain to the heroku servers. How can I check the records in my heroku database?
You can use heroku run rails console and look at your records with Model.all or any other method.
If you want to backup the database look at heroku PG backups, you then can import your database on your local machine and look at it there. Depending on your db adapter you could use sqlite browser for sqlite3 or phpmyadmin for MySQL.
I found a similar question like this and here is what #Chowlett says:
"You could run heroku pg:psql to fire up a Postgres console, then issue \d to see all tables, and \d tablename to see details for a particular table."
You can also type select * from tablename; to view the table contents.
How to view current database schema for Heroku app in Terminal?
heroku db:pull to pull your production DB locally to take a peek in it.
I'll give the method for connecting via a GUI tool
Run the following command to get the database credentials from Heroku:
heroku pg:credentials DATABASE_URL
Then you can use a GUI tool like PG Commander or PGAdmin to connect to the db
Heroku now has an add-on named PostgreSQL Studio (currently free & in beta) that would let you access your database from within the browser, without having to use CLI, much like PHP MyAdmin.
To attach this add-on to your application,
heroku addons:create pgstudio
Then go to the list of add-ons on Heroku, select PostgreSQL Studio, authorize it, select the database to connect with from the dropdown list of all databases and it will take you to the web-based interface to handle your selected database.
You may refer to this official article on Heroku:
https://devcenter.heroku.com/articles/pgstudio
The easy answer is:
heroku pg:info
You can also download a client side Postgres, like Postico, and using the information provided in that URL to enter password and database name etc, then you can create locally, just like phpMyAdmin.
I use the admin_data gem, works well in Heroku.
You can use heroku dataclips that allows to run queries online. Here you can find documentation https://devcenter.heroku.com/articles/dataclips.
Connect to the database using Sequel Pro. You can find your ClearDB url using heroku config command. The structure for connecting is as follows:
CLEARDB_DATABASE_URL => mysql://[username]:[password]#[host]/[database name]?reconnect=true

Resources