Me Breccan McLeod-Lundy Developer at 3months Recent projects include: consumer.org.nz, digitalnz.org and sponsafier.com
Ruby(is not rails) Variables i = 3 i * 4 etc
Iterating and blocks i = [1,2] i.each do |one_i| Something End i.each do { |i| something }
Classes class  Hello def hi puts “hello” end end
Classes(cont) hello_object = Hello.new hello.hi # hello
If blocks if something stuff elsif something_else Other stuffe else Other other stuff end
Ranges and symbols (1...80) is a range contains everything within it and can be iterated over. Colons start symbols which are minimal bits of data representing only themselves, often used as keys in hashes. :symbol
Rails Started 2004 Included in Mac OS X by default in 2006 Recently: twitter, ravelry etc.
Opinionated Sensible Defaults Don't Repeat Yourself
 
Generators rails appname script/generate model/controller name script/generate migration migration
Scaffold generation Not really my first choice, but good for demonstrations and prototyping. script/generate scaffold Movie name:string description:text
Migrations Go up and down add_column :table, :name, type remove_column :table, :name
Routes Create restful routes for a controller map.resources :controller_name Make default page the index map.root :controller => 'movies', :action => 'index (may also need to delete index.html in public)
Adding Reviews script/generate scaffold Review rating:integer movie_id:integer content:text In movie model add has_many :reviews In review model add belongs_to :movie
Reviews New method in the controller needs an array of movies to be added to: @movies = Movies.all.collect { |movie| [movie.name, movie.id]} The view needs a select: <%= f.select(:movie, @movies) %>
Partials Major part of reusing code. In a view: <% render :partial => “/reviews/form” %> Create partials with file names like _form.html.erb
Displaying reviews on a film In show method of the movie controller add: @reviews = @movie.reviews  (After setting @movie) In the view <% @reviews.each do |review| %> <%= render :partial => “review”, :locals => { :review => review } %> <% end %> Create the partial or even extract it from the default review show!
Other resources Rails Guides Agile web dev with rails book Railscasts Wellrailed google group Google
Breccan McLeod-Lundy www.breccan.com [email_address] breccan on twitter, github etc

Rails VUWIT workshop

  • 1.
    Me Breccan McLeod-LundyDeveloper at 3months Recent projects include: consumer.org.nz, digitalnz.org and sponsafier.com
  • 2.
    Ruby(is not rails)Variables i = 3 i * 4 etc
  • 3.
    Iterating and blocksi = [1,2] i.each do |one_i| Something End i.each do { |i| something }
  • 4.
    Classes class Hello def hi puts “hello” end end
  • 5.
    Classes(cont) hello_object =Hello.new hello.hi # hello
  • 6.
    If blocks ifsomething stuff elsif something_else Other stuffe else Other other stuff end
  • 7.
    Ranges and symbols(1...80) is a range contains everything within it and can be iterated over. Colons start symbols which are minimal bits of data representing only themselves, often used as keys in hashes. :symbol
  • 8.
    Rails Started 2004Included in Mac OS X by default in 2006 Recently: twitter, ravelry etc.
  • 9.
    Opinionated Sensible DefaultsDon't Repeat Yourself
  • 10.
  • 11.
    Generators rails appnamescript/generate model/controller name script/generate migration migration
  • 12.
    Scaffold generation Notreally my first choice, but good for demonstrations and prototyping. script/generate scaffold Movie name:string description:text
  • 13.
    Migrations Go upand down add_column :table, :name, type remove_column :table, :name
  • 14.
    Routes Create restfulroutes for a controller map.resources :controller_name Make default page the index map.root :controller => 'movies', :action => 'index (may also need to delete index.html in public)
  • 15.
    Adding Reviews script/generatescaffold Review rating:integer movie_id:integer content:text In movie model add has_many :reviews In review model add belongs_to :movie
  • 16.
    Reviews New methodin the controller needs an array of movies to be added to: @movies = Movies.all.collect { |movie| [movie.name, movie.id]} The view needs a select: <%= f.select(:movie, @movies) %>
  • 17.
    Partials Major partof reusing code. In a view: <% render :partial => “/reviews/form” %> Create partials with file names like _form.html.erb
  • 18.
    Displaying reviews ona film In show method of the movie controller add: @reviews = @movie.reviews (After setting @movie) In the view <% @reviews.each do |review| %> <%= render :partial => “review”, :locals => { :review => review } %> <% end %> Create the partial or even extract it from the default review show!
  • 19.
    Other resources RailsGuides Agile web dev with rails book Railscasts Wellrailed google group Google
  • 20.
    Breccan McLeod-Lundy www.breccan.com[email_address] breccan on twitter, github etc