Code Academy Week 10 Notes

Hidden field in a form: f.hidden_field(:list_id)

Nested resources:

But is a top-level list of grades any good?

Do this in routes.rb

1 is :student_id, 4 is :id for grade

It is the default syntax for Rails 3.1 and up


For code block, you indent instead of using braces. Indentation is meaningful. So use soft tabs.
We need parentheses if the function takes 0 parameters.

Put in two gems:


So we get haml:

In HAML, whitespace is significant
For classes for p tag, you could do this:

Back from break
If you have a list of items with an association:

you can use :dependent with :delete, :delete_all will delete without calling callbacks (like if you have some email actions), :nullify removes foreign key

Use twitter authentication
Create a sessions controller

The create action will be called by Twitter


Use the omniauth gem
This gem will add routes to your application.
1. Register your app with twitter at
You get Access Level, Consumer Key, Consumer Secret, Request Token URL, Authorize URL, Access Token URL, Callback URL
We set the callback URL
You need to put in instead of localhost for dev
2. In gem file
You need to add a gem for each “strategy”

There is no base omniauth that we need to add.
The strategy gems depend on the base omniauth gem, and they will fetch it.
3. Write an omniauth initializer
in config/initializers: any code there will be run once – no naming standard
Create a file called config/initializers/omniauth.rb
Add this:

In routes put

match will map to any HTTP verb

In application layout: add a signin link

So your user model could just have a column for Provider and UID
You could get other stuff from hash

They have provider :twitter, ENV[‘TWITTER_KEY’], ENV[‘TWITTER_SECRET’]
environment variables are part of operating system
To view them:
env | sort
in irb, type “ENV”
ENV[“PATH”] is the OS “path” environment variables
So you can add it in the environment. It only works on a specific machine. Good luck deploying to Heroku
In terminal:

print them out:

cron tasks:

1. create a file lib/tasks called cron.rake
4. desc “import tweets”
5. task :cron => environment do
7. end
heroku rake cron

This is from Entry form. Entry belongs_to runner, runner has many entries
So :runner_id is the field in Runner, id is from runner, name is also from runner
foreign key, table, what to save as the foreign key, what to display