Skip to content

Latest commit

 

History

History
261 lines (191 loc) · 14.7 KB

NOTES.md

File metadata and controls

261 lines (191 loc) · 14.7 KB

NOTES

I'm writing down notes as I work on this, so that when I look back I will have some idea how to use Rails and R, and how to solve a number of issues I've run into along the way.

MODELS COMMANDS

In case I need to make changes... These are the rails commands to create the database model:

bin/rails g model course name term year:integer institution instructor folder_name

bin/rails g model session session_code name participation performance
min_response min_response_string date:datetime course:references

bin/rails g model question name start stop
num_seconds:integer question_index:integer
response_a:integer response_b:integer
response_c:integer response_d:integer response_e:integer
correct_a:integer correct_b:integer correct_c:integer correct_d:integer
correct_e:integer is_deleted session:references bin/rails g migration AddDetailsToQuestion
question_type:integer question_pair:integer

need to set null default for question_pair in migration file

bin/rails g model vote clicker_id first_answer_time:float
total_time:float num_attempts:integer loaned_clicker_to
first_response response question:references

CONTROLLERS

bin/rails generate controller Courses bin/rails generate controller ClassPeriods bin/rails generate controller Sessions new bin/rails generate controller Questions

R NOTES

OTHER NOTES

HEROKU

  • local postgres: create role iclickerviewer with createdb login password iclickerviewer;

  • postgres is super weird about shell variables like PGUSER and .pgpass. The passwords in .pgpass are actually just there to be matched. These are NOT settings like with a .my.cnf file. So the default is always to connect with the currently logged in user (i.e. jspacco), not with the user I want, which is iclickerviewer. You can't set a database user or a database in .pgpass, just passwords to match.

    • Also, PGUSER also does not seem to make any difference. The only way to connect with a user other than the one who is logged in (i.e. the unix username jspacco) is to set --user on the command line with psql. This is not what the documentation seems to suggest. Ugh.
    • to start/stop the server: sudo su - postgres -c "/Library/PostgreSQL/9.6/bin/pg_ctl -D /Library/PostgreSQL/9.6/data stop"
  • heroku pg:info

    • heroku pg:credentials postgresql-parallel-76813
    • heroku pg:reset
    • heroku pg:psql
  • to push from local DB to heroku:

    PGUSER=iclickerviewer PGPASSWORD=iclickerviewer heroku pg:push iclickerviewer postgresql-parallel-76813

  • To connect command line to Heroku: https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku DATABASE_URL=$(heroku config:get DATABASE_URL -a your-app) your_process

  • Had to re-name all of the migrations so that they happen in the order in which the primary keys are needed (i.e. courses, then sessions which ref courses, then questions which ref sessions, then votes which ref questions).

    • could be postgres v9.4 (local) vs postgres v9.6 (heroku)
  • when pulling Heroku db to local: update schema_migrations set version = '20170706214116' where version = '20170706214115'; This is because I ended up changing one of the migration numbers for some reason earlier. I can't remember why I changed the migration number, and I have no idea why it works on heroku but doesn't work locally. It's probably the right move to get these synched up again so that I can just pull the heroku db without doing anything else.

  • Check rails config: RAILS_ENV=production rake about

  • The power of renaming a migration: https://stackoverflow.com/questions/753919/run-a-single-migration-file

  • To create a single user in the Rails console (rails console full)

User.new(name: "T Honor Goat", email: "[email protected]", username: "thgoat", password: "tiberius99", password_confirmation: "tiberius99")

Rails

  • Rails error: form_tag(session_path(@session), method: :patch) IS NOT THE SAME AS form_tag url: session_path(@session), method: :path

The first one is correct, and creates a form for patching, which uses HTTP POST but sets a special _method hidden parameter.

The 2nd one creates a standard POST, and passes it a hash with keys "url" and "method" and the given values. This is an example of a place where all of the syntactic sugar provided by Ruby and Rails has definitely confused me.