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.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
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.
George Mason University
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.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Ch. 5 Web Page Design – Templates and Style Sheets Mr. Ursone.
Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II.
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.
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.
Intro to Rails INFO 2310: Topics in Web Design and Programming.
Ruby on Rails (Slides modified by ements-2ed.shtml)
An Introduction to ASP.NET Web Pages 2 Module 1: Webmatrix Installation and Your First Web Site Tom Perkins.
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,
Web 2.0: Concepts and Applications 2 Publishing Online.
Ruby on Rails CSCI 6314 David Gaspar Jennifer Garcia Avila.
Core Publisher: Station Administrator Tools. Training 1: Site Administration Training 2: Programs Training 3: Content Tagging Training 4: Creating Posts.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
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.
09/28/ Cascade Server User's Conference1 Smart Cascade Server Implementations & Strategies 2009 Cascade Server User’s Conference Justin Klingman,
Views Carol Wolf Computer Science. Extended Ruby  Views files are written in extended Ruby, erb.  They end in.html.erb.  Ruby code is intermixed with.
1 Dr Alexiei Dingli Web Science Stream Helpers, Forms and Layouts.
PUBLISHING ONLINE Chapter 2. Overview Blogs and wikis are two Web 2.0 tools that allow users to publish content online Blogs function as online journals.
MVC & ActiveRecord by Christian Mohr & Mohamed Souiai.
1 Dr Alexiei Dingli Web Science Stream Advanced ROR.
Eurotrace Hands-On The Eurotrace File System. 2 The Eurotrace file system Under MS ACCESS EUROTRACE generates several different files when you create.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
Session 1 SESSION 1 Working with Dreamweaver 8.0.
CAKEPHP Blog tutorial. what you’ll need examples/blog/blog.html 2  A running web server  A database server.
Lecture 11 Rails Topics SaaSSaaS Readings: SaaS book Ch February CSCE 740 Software Engineering.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
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.
Associations INFO 2310: Topics in Web Design and Programming.
Chapter 15 © 2009 by Addison Wesley Longman, Inc Overview of Rails - Rails is a development framework for Web-based applications - Rails is written.
Photo Gallery INFO 2310: Topics in Web Design and Programming.
Ruby on Rails: Databases. Rails Database Familiar Table Concept Naming convention – lower case, plural (i.e. tweets) How to Access (find), Update, Delete.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
Testing Carol Wolf Computer Science. Testing built into Rails  Rails comes with three databases.  development  test  production  The test database.
RUBY ON RAILS (RoR) Ishwor Khadka. Why Ruby on Rails?
Core Publisher: Station Administrator Tools. Training 1: Site Administration Training 2: Programs Training 3: Content Tagging Training 4: Creating Posts.
Chapter 15 © 2013 by Pearson Overview of Rails - Rails is a development framework for Web-based applications - Based on MVC architecture for applications.
Table of Contents TopicSlide Administrator Login 2 Administrator Navigations 3 Managing AlternativeDr.com Blogs 4 Managing Dr. Lloyd May Blogs 5 Managing.
Create, Update and Delete Carol Wolf Computer Science.
1 © Xchanging 2010 no part of this document may be circulated, quoted or reproduced without prior written approval of Xchanging. MOSS Training – UI customization.
® IBM Software Group © 2006 IBM Corporation JSF Rich Text Area Component This Learning Module describes the use of the JSF Rich Text Area component – for.
Introduction to Ruby&Rails Yuri Veremeyenko Monica Verma.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
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:
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
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.
COMP 143 Web Development with Adobe Dreamweaver CC.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
Generating XML Data from a Database Eugenia Fernandez IUPUI.
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
MVC Architecture, Symfony Framework for PHP Web Apps
Bruce Scharlau, University of Aberdeen, 2017
Ruby on Rails by Manik Juneja
Ruby on Rails by Manik Juneja
Chapter 15 Introduction to Rails.
Presentation transcript:

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 the remainder of this guide. config/ Configure your application’s runtime rules, routes, database, and more. This is covered in more detail in Configuring Rails ApplicationsConfiguring Rails Applications db/ Contains your current database schema, as well as the database migrations. doc/ In-depth documentation for your application. lib/ Extended modules for your application.

Rails files log/Application log files. public/ The only folder seen to the world as- is. Contains the static files and compiled assets. script/ Contains the rails script that starts your app and can contain other scripts you use to deploy or run your application. test/ Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails ApplicationsTesting Rails Applications config.ru Rack configuration for Rack based servers used to start the application. Gemfile Gemfile.lock These files allow you to specify what gem dependencies are needed for your Rails application.

Configuring your DB SQLite: built-in support, lightweight, serverless development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000

Configuring your DB MySQL: not built in, you need to configure properly the onfig/database.yml development: adapter: postgresql encoding: unicode database: blog_development pool: 5 username: blog password

Create an empty DB $ rake db:create

Hello Rails! You need to create at minimum a controller and a view. You can do that in a single command. Enter this command in your terminal: rails generate controller home index

erb Rails will create several files for you app/views/home/index.html.erb: is the template that will be used to display the results of the index action (method) in the home controller. Edit this file in your text editor and edit it to contain a single line of code: Hello, Rails!

Setting your application homepage Open: config/routes.rb $ rm public/index.html # You can have the root of your site routed with "root" # just remember to delete public/index.html. # root :to => 'welcome#index' root :to => "home#index"

Scaffolding Rails scaffolding is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.

Blog Example Let’s create a blog app with Rails Using Scaffold to create a Post resource that represents a single blog post: rails generate scaffold Post name:string title:string content:text

What Scaffold generator created db/migrate/ _create_pos ts.rb Migration to create the posts table in your database (your name will include a different timestamp) app/models/post.rbThe Post model test/unit/post_test.rbUnit testing harness for the posts model test/fixtures/posts.ymlSample posts for use in testing config/routes.rb Edited to include routing information for posts app/controllers/posts_controller.rbThe Posts controller app/views/posts/index.html.erbA view to display an index of all posts app/views/posts/edit.html.erbA view to edit an existing post app/views/posts/show.html.erbA view to display a single post app/views/posts/new.html.erbA view to create a new post

What Scaffold generator created app/views/posts/_form.html.erb A partial to control the overall look and feel of the form used in edit and new views test/functional/posts_controller_test.rb Functional testing harness for the posts controller app/helpers/posts_helper.rb Helper functions to be used from the post views test/unit/helpers/posts_helper_test.rbUnit testing harness for the posts helper app/assets/javascripts/posts.js.coffeeCoffeeScript for the posts controller app/assets/stylesheets/posts.css.scss Cascading style sheet for the posts controller app/assets/stylesheets/scaffolds.css.scss Cascading style sheet to make the scaffolded views look better

Database Migration Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Use “rake”commands Look in the db/migrate/ _create_posts.rb (yours will have a slightly different name) – When you run this migration it will create a posts table with two string columns and a text column. – It also creates two timestamp fields to allow Rails to track post creation and update times.

Try a migration More info at: rake db:migrate

Add a link app/views/home/index.html.erb Hello, Rails!

The Model Check app/models/post.rb The Post class inherits from ActiveRecord::Base. Active Record supplies a great deal of functionality to your Rails models for free, including – basic database CRUD (Create, Read, Update, Destroy) operations, – data validation, – sophisticated search support – ability to relate multiple models to one another.

The Model attr_accessible: Remember Ruby OO? It specifies a whitelist of attributes that are allowed to be updated in bulk (via update_attributes for instance).

Add Validation Edit the model: Validation overview: acks.html#validations-overview class Post < ActiveRecord::Base attr_accessible :content, :name, :title validates :name, :presence => true validates :title, :presence => true, :length => { :minimum => 5 } end

Test validation $ rails console >> p = Post.new(:content => "A new post") => #<Post id: nil, name: nil, title: nil, content: "A new post", created_at: nil, updated_at: nil> >> p.errors.full_messages => ["Name can't be blank", "Title can't be blank", "Title is too short (minimum is

Listing all posts Open the file app/controllers/posts_controller.rb Layouts and rendering: def = Post.all respond_to do |format| format.html # index.html.erb format.json { render :json } end

Layout Application specific layout in: app/views/layouts/application.html.erb Edit! Make the body background a different color (other than white!)

Creating new posts Instantiate new Post: where?? Display a new Post: where?? Open: views/posts/_form.html.erb – Where are all these classes defined? – What is – What is the form_for block: used to create an HTML form. Within this block, you have access to methods to build various controls on the form smart enough to work out if you are doing a New Post or an Edit Postaction, and will set the form action tags and submit button names appropriately in the HTMLoutput.

Creating new posts What happens when you hit the create button? – POST or GET action? If not successfully created: return to new! If successfully created store to Rails flash hash

Display an individual post Where is the code that shows post? – There are to parts: show action – Erb part

Edit posts Two parts again! Find them. Actions: – Edit – Update

Delete posts What type of action? How is the new page displayed?

Resources html html app#top app#top 1/20/13-ways-of-looking-at-a-ruby-symbol 1/20/13-ways-of-looking-at-a-ruby-symbol