Your SlideShare is downloading. ×
Rails review
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Rails review

1,272
views

Published on

ATLRUG Emerald City Programming Group, April 23, 2011.

ATLRUG Emerald City Programming Group, April 23, 2011.

Published in: Technology, Education

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,272
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Rails Review Alan Hecht http://alanhecht.me
  • 2. Building a Rails Application
        • How would you build emerald_blogger
        • Rails 3 application architecture
  • 3. Application Setup
        • rails new emerald_blogger
        • Edit Gemfile
          • bundle install
        • Add project to Git
        • Set up project in GitHub
        • Link project to GitHub
  • 4. App. Configuration Client Files
        • Located in the ‘public’ directory
        • HTML, image, JavaScript, and stylesheet files
        • Default page public/index.html
  • 5. App. Configuration - Environments
        • Three environments: development, test, & production
        • Can add additional environments (i.e. acceptance)
  • 6. App. Configuration - Database
        • config/database.yml has database configuration
        • Databases located in db/
        • db/schema.rb contains the database schema after migrations are applied
        • db/seeds.rb contains database seed data which is run once
  • 7. App. Configuration - Defaults
        • Located in config/application.rb
        • New to Rails 3
  • 8. Application Code
        • Located in app/
          • app/models
          • app/views
          • app/controllers
          • app/helpers
            • Helper code for models, views, and controllers
            • Primarily seen it used for view helpers, with some controller helpers
  • 9. Post Setup - Model
        • rails generate model Post title:string, content:text, post_date:date
        • Model, migration, and test were created
  • 10. Post Setup - Validation
        • In Rails 3, validations are “validates <field(s)>, <condition>”
        • validates :title, :content, :presence => true
  • 11. Post Setup - Migration
        • rails generate migration AddLikesToPosts num_likes:integer
        • run with “rake db:migrate”
        • Can add an index to a table as a migration
  • 12. Post Setup - Routing
        • config/routes.rb
        • A “resource route” maps HTTP verbs to CRUD actions
        • Add a “resources :posts” line to file
        • rake routes – lists the routes and their actions
        • Must restart the application after changing the file
  • 13. Post Setup - Controller
        • Ties the view and the model together
        • Sets up the model(s) for use by the view
        • The view with the same action will be rendered unless a different view is specified
          • i.e. render :edit
          • Controller code for different view is not executed
        • Can specify what view layout to use along with alternatives to HTML like XML or JavaScript
  • 14. Views - Layouts
        • Page template
        • View code for an action executed by the “yield” statement
          • - Implemented using a Ruby block
  • 15. Post Setup - View
        • app/views/posts directory
  • 16. Views - Partials
        • app/views/posts/_form.html.erb
          • Underscore in file name signifies that it’s a partial
        • Represents a portion of the view on a specific page that serves a specific purpose or is reused.
        • Can pass parameters into partials
        • Most of the time, the partial is loaded in the view code
          • Can render a partial directly from the controller
  • 17. App. Configuration Default Home Page
        • Remove ‘public/index.html’
        • Add the line ‘root :to => “<controller>#<action” in config/routes.rb
        • Restart the application
  • 18. Comments Setup Active Record Associations
        • Must be associated in the model and the database
        • For a “one-to-many” relationship:
          • Add the foreign key to the parent in the child table
          • Add a “ has_many <children> ” line to the parent model
  • 19. Deploy to Heroku
        • Edit Gemfile
          • Add “gem heroku” line
        • bundle install
        • heroku create
        • git push –u heroku master
        • heroku open