CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; +----+-----------+------------+------+------+ | id | name.

Slides:



Advertisements
Similar presentations
CS 142 Lecture Notes: FormsSlide 1 Simple Form Product: Price:
Advertisements

Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
Trestle Generator Industrial-strength scaffolding for Ruby on Rails web application development.
Creating rails app. p:\InstantRails\rails_apps>rails -d mysql cars create create app/controllers create app/helpers create app/models create app/views/layouts.
Ruby on Rails CSE 190M, Spring 2009 Week 8. Models Up to this point, all of our work has been in our Controllers and View If you have inspected the Models.
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
1 JRuby on Rails GAO ANG Sun Functional Campus Ambassador 1.
CS 142 Lecture Notes: FormsSlide 1 Simple Form Value1: Value2:
CS 142 Lecture Notes: Relational DatabasesSlide 1 Relation (Table) namebirthgpagrad Anderson Jones Hernandez
CS 683 Emerging Technologies Fall Semester, 2005 Doc 24 Rails Database Nov 22, 2005 Copyright ©, All rights reserved SDSU & Roger Whitney, 5500 Campanile.
24-Jun-15 Rails. What is Rails? Rails is a framework for building web applications This involves: Getting information from the user (client), using HTML.
CS 142 Lecture Notes: FormsSlide 1 Simple Form Value1: Value2:
Rails Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce.
Creating a wiki blog. Run apps that come with instant rails distribution select I /rails applications/open ruby console window Cd to cookbook or typo.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
RUBY ON RAILS It’s so rad. What we’ll cover  What is Ruby?  What is RoR?  Why RoR?  Developing with RoR  Deployment  Demo  Questions.
RUBY ON RAILS CS 186 – Arsalan Tavakoli 3/18/2008 Slides adapted from CS 198 slides with the gracious permission of Armando Fox and Will Sobel.
Authentication/Authorization INFO 2310: Topics in Web Design and Programming.
1 Dr Alexiei Dingli Web Science Stream Models, Views and Controllers.
UC Berkeley Hello Rails. Review: MVC Goal: separate organization of data (model) from UI & presentation (view) by introducing controller –mediates user.
Taking ActiveRecord to the Next Level Blythe Dunham
Why rails? Carlos Kirkconnell. Google Happiness leads to Productivity Happiness Matters.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
CS 3630 Database Design and Implementation. 2 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1  A2  A3  …  An.
© Copyright IBM Corporation 2007 AP/Americas April 15-18, 2007 Anaheim, California Introduction to RubyOnRails - a J2EE replacement? Russell Scheerer –
CS 142 Lecture Notes: Relational DatabasesSlide 1 Relation (Table) namebirthgpagrad Anderson Jones Hernandez
Associations INFO 2310: Topics in Web Design and Programming.
1 Dr Alexiei Dingli Web Science Stream A ROR Blog.
Chapter 15 © 2009 by Addison Wesley Longman, Inc Overview of Rails - Rails is a development framework for Web-based applications - Rails is written.
Ruby on Rails vs ASP.NET MVC Simone Chiaretta Web Architect, Council of the EU Milano, 19 Febbraio 2011 Sandro.
Photo Gallery INFO 2310: Topics in Web Design and Programming.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Ruby on Rails: Databases. Rails Database Familiar Table Concept Naming convention – lower case, plural (i.e. tweets) How to Access (find), Update, Delete.
Web Application Development Technology เทคโนโลยีสำหรับการพัฒนาโปรแกรม ประยุกต์เว็บ Suntorn Witosurapot Phone: or
1 Dr Alexiei Dingli Web Science Stream Web We’ll implement a voting mechanism Using AJAX Web 2.0.
RUBY ON RAILS (RoR) Ishwor Khadka. Why Ruby on Rails?
Chapter 15 © 2013 by Pearson Overview of Rails - Rails is a development framework for Web-based applications - Based on MVC architecture for applications.
1 Migration. 2 What’s Migration? Migration –Isolates database differences Allows you to write schema updates without worries about differences –Helps.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Introduction to Ruby&Rails Yuri Veremeyenko Monica Verma.
Adding Data to a Database Table Carol Wolf Computer Science.
CS 142 Lecture Notes: FormsSlide 1 Simple Form Product: Price:
Ruby on Rails & Databases. Active Record Active Record in Rails CRUD & Other Stuff Mapping Cardinalities Migrations Demo.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
Introduction to information systems RUBY ON RAILS dr inż. Tomasz Pieciukiewicz.
Migrations Carol Wolf CS 396X. ISBNTitleAuthorImage EmmaAustenemma.jpg Oliver TwistDickenstwist.jpg HamletShakespearehamlet.jpg.
Detecting Polymorphisms in Mouse Genome Phillip Tao Advisor: Eleazar Eskin Grad Student: Emrah Kostem.
Advanced Migration By Aye Mon Tun.  To change database schema in consistent and easy way  In ruby code Migration? 11/25/2013 2Web Application Engineering.
Introduction to Databases & SQL Ahmet Sacan. What you’ll need Firefox, SQLite plugin Mirdb and Targetscan databases.
SEG4110 – Advanced Software Design and Reengineering TOPIC N Ruby on Rails.
Shared innovation Dynamic languages, Ruby, and Rails (and why web developers like them) Dr. Elliot Smith Software Engineer, Talis September 2008.
Melbourne LUG Presentation Learning Rails and Ruby - making webapps easier.
Mid-Hudson Valley Linux Users Group Ruby on Rails Web Development is Fun Again MHVLUG Meeting Jan 7 th 2009 Sean Dague sean.dague.net.
Data Modeling.
Relation (Table) Row/Tuple/Record Column/Attribute/Field name birth
Ruby on Rails Model of MVC
Relation (Table) Row/Tuple/Record Column/Attribute/Field name birth
Agile Web Development with Ruby and Rails
Model for Student Table
מודל היחסים The Relational Model.
Chapter 15 Introduction to Rails.
Chapter 2 Modeling Data in the Organization
CS 142 Lecture Notes: Relational Databases
Model for Student Table
Painted Shadows - Not Allowed
Why We Need Car Parking Systems - Wohr Parking Systems
Types of Stack Parking Systems Offered by Wohr Parking Systems
Add Title.
Presentation transcript:

CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name | birth | gpa | grad | | 1 | Anderson | | 3.9 | 2009 | | 2 | Jones | | 2.4 | 2012 | | 3 | Hernandez | | 3.1 | 2011 | | 4 | Chen | | 3.2 | 2011 | Rails model class ( app/models/student.rb) : class Student < ActiveRecord::Base end ruby script/generate model student

CS 142 Lecture Notes: Rails ActiveRecordSlide 2 Many-to-One Relationships SELECT * FROM students; | id | name | birth | gpa | grad | advisor_id | | 1 | Anderson | | 3.9 | 2009 | 2 | | 2 | Jones | | 2.4 | 2012 | 1 | | 3 | Hernandez | | 3.1 | 2011 | 1 | | 4 | Chen | | 3.2 | 2011 | 1 | SELECT * FROM advisors; | id | name | title | | 1 | Fujimura | assocprof | | 2 | Bolosky | prof | class Student < ActiveRecord::Base belongs_to :advisor end class Advisor < ActiveRecord::Base has_many :students end class Student < ActiveRecord::Base belongs_to :advisor end class Advisor < ActiveRecord::Base has_many :students end

CS 142 Lecture Notes: Rails ActiveRecordSlide 3 Many-to-Many Relationships SELECT * FROM students; | id | name | birth | gpa | grad | | 1 | Anderson | | 3.9 | 2009 | | 2 | Jones | | 2.4 | 2012 | | 3 | Hernandez | | 3.1 | 2011 | | 4 | Chen | | 3.2 | 2011 | SELECT * FROM courses; | id | number | name | quarter | | 1 | CS142 | Web stuff | Winter 2009 | | 2 | ART101 | Finger painting | Fall 2008 | | 3 | ART101 | Finger painting | Winter 2009 | | 4 | PE204 | Mud wrestling | Winter 2009 | SELECT * FROM courses_students; | course_id | student_id | | 1 | 1 | | 3 | 1 | | 4 | 1 | | 1 | 2 | | 2 | 2 | | 1 | 3 | | 2 | 4 | | 4 | 4 | class Student < ActiveRecord::Base has_and_belongs_to_many :courses end class Course < ActiveRecord::Base has_and_belongs_to_many :students end class Student < ActiveRecord::Base has_and_belongs_to_many :courses end class Course < ActiveRecord::Base has_and_belongs_to_many :students end

CS 142 Lecture Notes: Rails ActiveRecordSlide 4 Migration: Create New Table class CreateStudents < ActiveRecord::Migration def self.up create_table :students do |t| t.column :name, :string t.column :birth, :date t.column :gpa, :float t.column :grad, :integer end def self.down drop_table :students end

CS 142 Lecture Notes: Rails ActiveRecordSlide 5 Migration: Add Column class AddAdvisor < ActiveRecord::Migration def self.up add_column :students, :advisor, :integer end def self.down remove_column :students, :advisor end

CS 142 Lecture Notes: Rails ActiveRecordSlide 6 Migration Utilities ruby script/generate migration create_students rake db:migrate rake db:migrate VERSION= rake db:migrate VERSION=0

CS 142 Lecture Notes: Rails ActiveRecordSlide 7