Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Super Duper Basics of Rails

Super Duper Basics of Rails

A talk I gave at Belfast Ruby on my experiences learning Rails

Tommy Palmer

February 01, 2012
Tweet

More Decks by Tommy Palmer

Other Decks in Programming

Transcript

  1. STUFF THAT I WISH I KNEW ABOUT RAILS TWO YEARS

    AGO & WHY I WANTED TO LEARN IT
  2. Rails lets you do common web app things • working

    with databases • rendering HTML • sending email • and more...
  3. EH?

  4. Gems give extra functionality to Ruby: • working with apis

    • tools for blogging • stylesheets (sass)
  5. <% @posts.each do |post| %> <div class="post"> <h1><%= post.title %></h1>

    <p><%= post.body %></p> <b><%= post.pub_date %></b> </div> <% end %>
  6. This generates our Model, Views, Controller and some other stuff...

    rails g scaffold post title:string body:text pub_date:date
  7. class CreatePosts < ActiveRecord::Migration def change create_table :posts do |t|

    t.string :title t.text :body t.date :pub_date t.timestamps end end end
  8. rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false). rake

    db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n). rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:seed # Load the seed data from db/seeds.rb rake db:setup # Create the database, load the schema, and initialize with the seed data More rake commands
  9. Model - post.rb Controller - posts_controller.rb Views - show, index,

    new & edit.html.erb Migration - (unix timestamp)_create_posts.rb routes.rb - resources :posts rails g scaffold post