A Little Engineering on Rails

A Little Engineering on Rails

Advanced Web Development Robert W. Hasker Milwaukee School of Engineering Goals • Course overview • Introduction to the Rails framework • Introduction to Ruby Course Overview • Review Syllabus ▫ Subgoal: engineering active websites • Reading: ▫ Textbook: Agile Web Development with Rails 4 ▫ Supplement: Programming Ruby: The Pragmatic Programmer's Guide Read chapters 1-5 • Lab prep: do assignment 0 • First: what is Rails? The Rails Framework • Basic goal: construct database-backed websites • Multi-platform: popular OS’s, database engines • Origins: ▫ Instiki by David Heinemeier Hansson ▫ Basecamp by 37signals ▫ Rails: domain-independent core • Built on the Ruby language ▫ General-purpose language: scripting, applications ▫ Dynamically typed, “open” classes Basic Concept: MVC • Issue: how to separate logic from presentation? • Classic solution: Model/View/Controller ▫ Model: domain-level data ▫ View: how the data is presented to the user Typically want multiple views ▫ Controller: logic linking the two • Rails ▫ Model = tables in a relational database ▫ View = web pages ▫ Controller = controller Basic Concepts: Active Record • Relational Databases: organize large amounts of data ▫ Issue: no easy mapping to object-oriented design • Active Record Pattern ▫ A design pattern first described by Martin Fowler ▫ Object = table row w/ attributes stored as columns ▫ Table = collection of objects ▫ OOD = database (collection of tables) Rails: link classes through id fields in tables Active Record Example • Data for a simple voting system: • As tables: ▫ create table questions (id int, body text, start datetime, end datetime, primary key(id)); ▫ create table voters (id int, username text, password text, primary key(id)); ▫ create table vote_records (voter_id int, …); • Benefit: can add operations as needed - active records Using rails to build a voting application • See //faculty-web.msoe.edu/hasker/webdev/notes/rails-voting- demo.html Review • Rails: a tool for building quick, OO websites • Sound design ▫ MVC: organization ▫ ActiveRecord: combining OO & relational database • Minimal setup ▫ convention, not configuration ▫ many relationships are declared explicitly • Development support ▫ Prototyping with scaffolding ▫ Tools: helpers ▫ has full debugging support; separate dev/prod dbs • Next: programming in Ruby.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us