Code Academy Week 10 Notes

2012-03-13_08.54.13
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

students/1
students/1/grades
students/1/grades/4
1 is :student_id, 4 is :id for grade

Coffeescript:
coffeescript.org
It is the default syntax for Rails 3.1 and up

becomes

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.

HAML:
Put in two gems:

 

So we get haml:

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

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

Routes:

Use the omniauth gem
This gem will add routes to your application.
1. Register your app with twitter at https://dev.twitter.com
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 127.0.0.1 instead of localhost for dev
2. In gem file
You need to add a gem for each “strategy” https://github.com/intridea/omniauth/wiki/List-of-Strategies

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:

2012-03-15_08.28.54
cron tasks:
devcenter.heroku.com/articles/cron

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

a
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