Difference between revisions of "DevSummit07:Intro To Ruby On Rails"

From DevSummit
Jump to navigation Jump to search
m (1 revision imported)
 
(No difference)

Latest revision as of 23:08, 20 May 2015

Facilitated by Evan Henshaw-Plath, protest.net, and Josh Crawford, Brattleboro Tech Collective

Ruby on Rails is fast becoming a platform of choice for rapid application development in the nonprofit sector. Evan and Josh will cover Ruby basics, including the proverbial "Hello World" walk-through, and open up the floor for questions and discussion.

Session Notes

Ruby on Rails (Intro)

Ruby on Rails - rapid development environment

Ruby: programming language, Rails is the web app dev framework

Created by 37 Signals (Basecamp folks)

90% of app is CRUD (create, retrieve, update, delete)


Lightweight configuration - follow RoR conventions instead of tons of conf files

example: phpBB in php @ 10K-20K LOC -- but in Ruby only 500 LOC

Rails - MVC Model View Controller

Model (data & biz logic) View (templates & display) Controller (links Model & View)

Separate display/output from data/bizlogic

example - display the same data in different manners (e.g., Atom, RSS, HTML, VXML, etc)

Uses: Great for standard web apps... not as good for CMS, content, highly-stateful applications

Rails CMS examples: Mephisto, Radiant

Ruby has many extensions for functionality - but these are toolkit/libraries for devs to build tools, not end user apps


From here, we're going to build an app from scratch (environment already installed)

  1. rails demo //creates new project including files and subdirs

/* develop locally, RoR has methods for publishing to server, easily reverting, test environments, etc. */

  1. cd demo
  1. nano config/database.yml //enter local db connection info

//supports tons of databases, oracle, mssql, mysql, sqlite, pgsql

//we're making a donation aplication

mysql> use dbname mysql> create table donations (id... fields, etc.)

  1. script/generate scaffold Donation // creates basic framework for this

//app, views, controller

/* RoR has "opinions" -- aka conventions. e.g., use underscores, not camel case */

Modes - traditional web app has ONE app, one environment RoR has THREE

  • production mode - serving live content, not changing code, no visible error messages to users, works faster
  • development mode - files can be changed, run slower, use debug tools, output very detailed debugging info
  • test mode - used for automated unit-tests for testing... preset tests, then run them all simultaneously (much faster)


Validation : add validation lines to model for your specific class...

RoR has "migrations" < lets you define how you want the database to work, which is very useful when moving from your local dev environment to the server... you can also revert schemas, historically.

Every table in a RoR app must have a unique, numeric, auto-incrementing primary key. If your db does NOT do that automagically, RoR will handle the autoincrement part via code.

Links

<%= link_to 'Show', :action => 'show', :id => @donation %>

"The Unobtrusive Javascript" < a RoR plugin that does magic accessibility helping... one of MANY, MANY RoR plugins...

No explicit methods in there... RoR adds most of its methods dynamically upon execution.

Not as many hosts as php due to resource intensiveness...

Hosting best practice: use load balancer/mongrel system OR FastCGI...