Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

BCR Ruby on Rails - Boston Computing Review : Ruby on Rails

on

  • 783 views

 

Statistics

Views

Total Views
783
Views on SlideShare
783
Embed Views
0

Actions

Likes
0
Downloads
15
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

BCR Ruby on Rails - Boston Computing Review : Ruby on Rails BCR Ruby on Rails - Boston Computing Review : Ruby on Rails Presentation Transcript

  • BCR : Ruby on Rails an introduction more at http://www.rubyonrails.org/
  • Background / Agenda
    • Upcoming web project
    • Fears
    • Welcome Ruby
    • Getting Onto Rails
      • Framework, MVC, Databases, Application Servers and more
    • Deploying ROR
    • Where to look Next
  • Considerations
    • .NET
      • Experience
    • J2EE
      • Enterprise Acceptance
    • PHP
      • Proven, knowledgebase
    • Ruby on Rails
      • Development Speed, native MVC *and a little fun*
  • Fears
    • PHP vs ROR
    • Stability
    • Lack of Public Knowledge Base
    • “ Shark Attack”
    • Missing Intelisense…
  • Ruby
    • Based on SmallTalk, Perl, Lisp
    • Object Oriented
    • Not strongly typed
    • Basics http://www.fincher.org/tips/Languages/Ruby/
    • “ FUN”? :)
  • Rails Framework
    • Power Through Rules and Best Practice
    • MVC
    • Assumes a Database
    • Object Relational Mapping
    • Forms Handling – Been there done that
    • Parameters
    • Link Building
    • Scaffolding
  • MVC
    • Nothing New, 1973
    • Model
      • Your Data and Data Rules
    • View
      • Interface
    • Controller
      • Traffic Director
  • MVC in ROR View ShowUser.rhtml <html> … User Name <% = @user.name %> … </html> Controller Users_controller.rb … def ShowUser @user = User.find(params[ :id ]) end def other end def another end … Model user.rb class User < ActiveRecord::Base #relations has_many :posts #start validation here validates_presence_of :email, :username, :password validates_uniqueness_of :email, :username End
  • Model
    • Object Relational Mapping
    • “ ActiveRecord”
    • Less Database “glue” Code *sigh of relief!*
    • Worst Case Scenario Optimizations Possible with manual SQL
    • Logging for Performance Checking
  • Model : Rules
    • Table Names
      • Plurals
    • Attribute Names
      • id for primary key in table
      • table_id for foreign key in other table
    • Ability to run joins via objects!
      • Article.User.Username
    • Legacy Options Available
  • Model : Sample from Text
  • Model : Sample from Text
  • Model : Sample from Text
  • Model : Code Sample
    • class User < ActiveRecord::Base
    • #relations
    • has_many :posts
    • #related to rankings
    • has_many :ranks
    • has_many :critiques
    • #start validation here
    • validates_format_of( :email ,
    • :with => /^([^@s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i,
    • :message =>&quot;has an invalid format&quot;)
    • validates_presence_of :email , :username , :password
    • validates_uniqueness_of :email , :username
    • #authentication for user
    • def self.authenticate(username, password)
    • user = User.find( :first , :conditions => [&quot;username = ?&quot;, username])
    • if user
    • if user.password != password
    • user = nil
    • end
    • end
    • user
    • end
    • end
  • Model : DB Logging
    • Processing SearchController#list (for 127.0.0.1 at 2006-11-18 22:51:36) [POST]
    • Session ID: 667befe9190e1c686f537e8dcdcd731d
    • Parameters: {&quot;commit&quot;=>&quot;search&quot;, &quot;action&quot;=>&quot;list&quot;, &quot;controller&quot;=>&quot;search&quot;, &quot;query&quot;=>{&quot;query&quot;=>&quot;test&quot;}}
    • [4;36;1mArticle Load (0.000000)[0m [0;1mselect a.* from articles a where (lower(a.title) like '%querytest%' or lower(a.articlebody) like '%querytest%' or lower(a.description) like '%querytest%') order by a.created_on desc[0m
    • Rendering within layouts/search
    • Rendering search/list
    • Completed in 0.03100 (32 reqs/sec) | Rendering: 0.01500 (48%) | DB: 0.00000 (0%) | 200 OK [http://localhost/search/list]
  • Controller
    • Method name matches view folder
      • users_controller.rb works for /views/users/***.rhtml
      • called “actions”
      • all view’s methods will sit there
    • Ability to
      • CRUD
      • Flash
      • Redirect
  • Controller : ActiveRecord Create
    • def create
    • @user = User. new (params[ :user ])
    • if @user .save
    • flash[ :notice ] = 'User was successfully created.'
    • redirect_to :action => 'list'
    • else
    • render :action => 'new'
    • end
    • end
  • Controller : Flash
    • def create
    • @user = User. new (params[ :user ])
    • if @user .save
    • flash[ :notice ] = 'User was successfully created.'
    • redirect_to :action => 'list'
    • else
    • render :action => 'new'
    • end
    • end
  • Controller : Redirect
    • def create
    • @user = User. new (params[ :user ])
    • if @user .save
    • flash[ :notice ] = 'User was successfully created.'
    • redirect_to :action => 'list'
    • else
    • render :action => 'new'
    • end
    • end
  • Controller : Getting Data
    • Request Data (POST / GET)
      • Params hash
    • Models
    • Session data
    • etc
  • Views
    • Show the data
    • Templates (layouts)
    • Use objects from controller
    • Navigate guide into controller / action
    • Forms
  • Views : Showing Data
    • Inline Ruby (similar to JSP)
    • <% for column in User.content_columns %>
    • <p>
    • <b><%= column.human_name %>:</b> <%=h @user.send(column.name) %>
    • </p>
    • <% end %>
    • <%= link_to 'Edit', :action => 'edit', :id => @user %> |
    • <%= link_to 'Back', :action => 'list' %>
  • Views : Layouts
    • Inherit by default for controller
    • Exception in controller
      • #set the layout
      • layout &quot;articles&quot;, :except => [:signin, :richtest]
  • View : Layout Sample
    • <html>
    • <head>
    • <title>Admin: <%= controller.action_name %></title>
    • <%= stylesheet_link_tag 'scaffold' %>
    • </head>
    • <body>
    • <p style=&quot;color: green&quot;><%= flash[ :notice ] %></p>
    • <%= @content_for_layout %>
    • </body>
    • </html>
  • View : Object from Controller
    • <% for column in User.content_columns %>
    • <p>
    • <b><%= column.human_name %>:</b> <%=h @user.send(column.name) %>
    • </p>
    • <% end %>
    • <%= link_to 'Edit', :action => 'edit', :id => @user %> |
    • <%= link_to 'Back', :action => 'list' %>
  • View : Navigation
    • <% for column in User.content_columns %>
    • <p>
    • <b><%= column.human_name %>:</b> <%=h @user.send(column.name) %>
    • </p>
    • <% end %>
    • <%= link_to 'Edit', :action => 'edit', :id => @user %> |
    • <%= link_to 'Back', :action => 'list' %>
  • View : Forms
    • Native validation based on model
    • Partials to separate code from main view view _formname.rhtml
      • <h1>Quick Account Signup</h1>
      • <%= start_form_tag :action => 'create' %>
      • <%= render :partial => 'formname' %>
      • <%= submit_tag &quot;Create&quot; %>
      • <%= end_form_tag %>
  • View : Forms
    • <%= error_messages_for 'user' %>
    • <!--[form:user]-->
    • <p><label for=&quot;user_firstname&quot;>Firstname</label><br/>
    • <%= text_field 'user', 'firstname' %></p>
    • <p><label for=&quot;user_lastname&quot;>Lastname</label><br/>
    • <%= text_field 'user', 'lastname' %></p>
    • <p><label for=&quot;user_email&quot;>Email</label><br/>
    • <%= text_field 'user', 'email' %></p>
    • <p><label for=&quot;user_username&quot;>Username</label><br/>
    • <%= text_field 'user', 'username' %></p>
    • <p><label for=&quot;user_password&quot;>Password</label><br/>
    • <%= password_field 'user', 'password' %></p><br>
    • <!--[eoform:user]-->
  • Scaffolding
    • Fast
      • Famous video (blog in 15 min) http://media.rubyonrails.org/video/rails_take2_with_sound.mov
    • Dynamic view from DB
    • Great starting place
    • Needs more work
  • Deploying
    • Time consuming but straightforward
    • Unix / Linux hosts
    • TextDrive
    • LightHTTPD server
    • MySQL
  • Miscellaneous / Thoughts
    • Logging Framework Ready to Use
    • Interpreted (no waiting for compile)
    • Once you get the hang of Ruby a lot of fun to quickly develop
    • In the weeds is still in the weeds
  • Where to Look Next
    • O’Reilly Onlamp - Great Starting Place
      • http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html
      • http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html
    • Books from 37 Signals
      • Agile Web Development With Rails
      • Rails Recipies
      • http:// www.rubyonrails.org /docs
  • On the CD
    • IDE – RadRails
      • Built on Eclipse
    • Database – MySQL 5.0 with GUI Tools
      • Ever wonder why the SQL Server 2005 GUI looks like it does? :)
    • O’Reilly Onlamp Articles
    • Ruby on Rails Cheat Sheet
    • Famous Blog Video
    • This Powerpoint Deck