Methods for Rails. File Structures This is taken directly from app Holds all the code that's specific.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Advertisements

The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Ruby (on Rails) CSE 190M, Spring 2009 Week 3. Web Programming in Ruby Ruby can be used to write dynamic web pages Similar to PHP, chunks of Ruby begins.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
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.
Chapter 15 © 2010 by Addison Wesley Longman, Inc Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in Use spread rapidly.
Trestle Generator Industrial-strength scaffolding for Ruby on Rails web application development.
15-Jun-15 Rails and Ajax. HTML Forms The... tag encloses form elements (and usually includes other HTML as well) The arguments to form tell what to do.
JSP Java Server Pages Reference:
Ruby on Rails a popular web application framework, aimed to increase the speed and ease of web development Ruby on Rails, Tim Zappe.
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.
Multiple Tiers in Action
Apache Tomcat Server Typical html Request/Response cycle
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 CSE 190M, Spring 2009 Week 5. Installing Rails First, install Ruby with RubyGems Then, install the Rails gem gem install rails -version=2.3.2.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Ruby on Rails (Slides modified by ements-2ed.shtml)
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
Ruby on Rails. What is Ruby on Rails? Ruby on Rails is an open source full-stack web framework. It is an alternative to PHP/MySQL. It can render templates,
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
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.
Server-side Scripting Powering the webs favourite services.
Basics of Web Databases With the advent of Web database technology, Web pages are no longer static, but dynamic with connection to a back-end database.
Ajax and Ruby on Rails Session 9 INFM 603.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JSP Java Server Pages Softsmith Infotech.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
MVC & ActiveRecord by Christian Mohr & Mohamed Souiai.
1 Accelerated Web Development Course JavaScript and Client side programming Day 2 Rich Roth On The Net
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Ruby on Rails Your first app. Rails files app/ Contains the controllers, models, views and assets for your application. You’ll focus on this folder for.
PHP + Framework + MVC CakePHP Lectures 1. What is Framework? CakePHP Lectures 2.
Ruby on Rails CSE 190M, Spring 2009 Week 6. Overview How to use a database Demo creating a blog application on Rails Explain how the application works.
The Active Record Paradigm Databases in Database-Centric Web Site Development.
Ruby on Rails (Slides modified by ements-2ed.shtml)
Associations INFO 2310: Topics in Web Design and Programming.
Routes & REST & URL-helpers & validations & filters
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
Ruby/Ruby on Rails Yasushi Osonoi Open Dream corporation
Chapter 15 © 2013 by Pearson Overview of Rails - Rails is a development framework for Web-based applications - Based on MVC architecture for applications.
Create, Update and Delete Carol Wolf Computer Science.
Ruby on Rails+MySQL. Sebesta corvette example In rails_apps create a directory (car_app), change to this dir and run rails (rails cars) Rails_apps Car_app.
HTML Links HTML uses a hyperlink to another document on the Web.
Chap 2 – Getting Started COMP YL Professor Mattos.
Ruby on Rails Controller of MVC. Routes How we map URIs like /tweets/1 to calling the show method of the Controller.
Rails and routing INFO 2310: Topics in Web Design and Programming.
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.
The Controller Carol Wolf Computer Science. Rails generate commands  Using the generate command, you can create a number of useful objects.  Rails:
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
School of Informatics University of Edinburgh An Introduction to Ruby on Rails Ken Dawson.
Introduction to Dynamic Web Programming
Rails web application framework that uses Ruby as its programming language builds skeleton applications for you applications come with lots of defaults.
Software Design.
Play Framework: Introduction
CMPE 280 Web UI Design and Development October 24 Class Meeting
PHP / MySQL Introduction
Bruce Scharlau, University of Aberdeen, 2017
Rails 11-Nov-18.
Model – View – Controller Pattern
Chapter 15 Introduction to Rails.
Back end Development CS Programming Languages for Web Applications
CNIT 133 Interactive Web Pags – JavaScript and AJAX
Back end Development CS Programming Languages for Web Applications
Presentation transcript:

Methods for Rails

File Structures This is taken directly from app Holds all the code that's specific to this particular application. app/controllers Holds controllers that should be named like weblog_controller.rb for automated URL mapping. All controllers should descend from ActionController::Base. app/models Holds models that should be named like post.rb. Most models will descend from ActiveRecord::Base. app/views Holds the template files for the view that should be named like weblog/index.rhtml for the WeblogController#index action. All views use eRuby syntax. This directory can also be used to keep stylesheets, images, and so on that can be symlinked to public. app/helpers Holds view helpers that should be named like weblog_helper.rb.

Typical flow of control A request from the browser goes to a controller in app/controllers The controller talks to the model in app/models (initially, by means of a scaffold) The model sends requests to the database (in db ) The database returns information to the model The model manipulates the information and returns it to the controller The controller uses a.rhtml template in app/views to send a response to the browser

The controller A request from the browser goes to a controller Create the controller with ruby script/generate controller ClassName (use \ instead of / on Windows) The controller will be app/controllers/class_name_controller.rb The controller extends ActionController::Base Make the browser request with If method is omitted, the default is index method must be defined in class_name_controller.rb

The model If you are going to use a database (most Rails applications do), create the database first Create the model with ruby script/generate model ClassName The model extends ActiveRecord::Base Inside the generated class, add the line scaffold :table where table is the name of a table in the database

Scaffolding The scaffold method is in ActionController::Scaffolding::ClassMethods scaffold adds these methods: index, list, show, destroy, new, create, edit, update

The view(s) Views are written as HTML templates, in files with the.rhtml extension The RHTML file uses ERb, embedded Ruby: Ruby statements (code to be executed, but not included in the HTML page) are enclosed in Ruby values, to be included in the resultant HTML, are enclosed in Some available methods are: start_form_tag, submit_tag, render, link_to, and end_form_tag

Where methods come from Controllers extend ActionController::Base Models extend ActiveRecord::Base All the relevant methods should be documented somewhere in Modules (mixins) make this more complicated, because a class can “mix in” methods from a variety of modules For example, validates_numericality_of is in module ActiveRecord::Validations::ClassMethods

The End