Lecture 7. Action View, Bootstrap & Deploying 1 / 40

Similar documents
Lecture 4. Ruby on Rails 1 / 49

Lecture 4. Ruby on Rails 1 / 52

Lecture 9. Forms & APIs 1 / 38

Programming web design MICHAEL BERNSTEIN CS 247

Lecture 6. Active Record Associations 1 / 34

Lecture 6. Active Record Associations 1 / 30

This project will use an API from to retrieve a list of movie posters to display on screen.

Front-End UI: Bootstrap

Episode 298. Getting Started With Spree

Responsive Web Design and Bootstrap MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University

Rails: Views and Controllers

Contents in Detail. Foreword by Xavier Noria

Advanced Angular & Angular 6 Preview. Bibhas Bhattacharya

NukaCode - Front End - Bootstrap Documentation

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

Lecture 8. Validations & Sessions 1 / 41

Mateen Eslamy 10/31/13

Session 5. Web Page Generation. Reading & Reference

Building Web Applications

Introduction and first application. Luigi De Russis. Rails 101

Working Bootstrap Contact form with PHP and AJAX

Rails 4 Quickly. Bala Paranj

Rails Guide. MVC Architecture. Migrations. Hey, thanks a lot for picking up this guide!

Static Site Generation

Responsive Web Design (RWD)

Css Manually Highlight Current Link Nav Link

Introduction to Computer Science Web Development

Client Side MVC with Backbone & Rails. Tom

FRONT END DEVELOPER CAREER BLUEPRINT

Rails Engines. Use Case. The Implementation

COM401 Software Engineering Laboratory

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 1

CUSTOMER PORTAL. Custom HTML splashpage Guide

MPT Web Design. Week 1: Introduction to HTML and Web Design

Simple AngularJS thanks to Best Practices

Mastering the APEX Universal Theme

iflame INSTITUTE OF TECHNOLOGY

Web Programming BootStrap Unit Exercises

Day 8: 7/June/2012. Log-in Authentication

Create First Web Page With Bootstrap

Techniques for Optimizing Reusable Content in LibGuides

COMP519 Web Programming Lecture 8: Cascading Style Sheets: Part 4 Handouts

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

Classroom Blogging. Training wiki:

EXPLORE MODERN RESPONSIVE WEB DESIGN TECHNIQUES

Kaltura MediaSpace Styling Guide. Version: August 2016

Static Site Generation

Making a live edit contact list with Coldbox REST & Vue.js

Migration Methods* Column Options. Active Record Supported Types. Add Column. Remove Column. Create Table. Don t Forget to Rake!

CS193X: Web Programming Fundamentals

Challenge: Working with the MIS2402 Template

AngularJS. CRUD Application example with AngularJS and Rails 4. Slides By: Jonathan McCarthy

Sass. The Future of Stylesheets.

Project Part 2 (of 2) - Movie Poster And Actor! - Lookup

Web Designing. Course Content. Basic HTML Tags. Getting started with CSS. Dealing with Images

Hello, world! 3.1. Ruby on Rails Web SimpleGreeter Hello, world! Rails SimpleGreeter Web Rails projects. ruby $ mkdir -p ~/projects

AngularJS. CRUD Application example with AngularJS and Rails 4. Slides By: Jonathan McCarthy

Css Manually Highlight Current Page Menu Using

Lesson 1 using Dreamweaver CS3. To get started on your web page select the link below and copy (Save Picture As) the images to your image folder.

INTRODUCTION TO WEB DEVELOPMENT IN C++ WITH WT 4

WEB DEVELOPER BLUEPRINT

Purpose of this doc. Most minimal. Start building your own portfolio page!

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Laravel

Web Software Model CS 4640 Programming Languages for Web Applications

Courslets, a golf improvement web service. Peter Battaglia

WEB/DEVICE DEVELOPMENT CLIENT SIDE MIS/CIT 310

Class #7 Guidebook Page Expansion. By Ryan Stevenson

django-responsive2 Documentation

Ruby on Rails. SITC Workshop Series American University of Nigeria FALL 2017

Reading How the Web Works

welcome to BOILERCAMP HOW TO WEB DEV

Website Management with the CMS

Introduction to AngularJS

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) More on Relative Linking. Learning Objectives (2 of 2)

Ektron Content Marketing Platform Product Notes

Ektron Content Marketing Platform Product Notes

Ten good practices for ASP.NET MVC applications

Advanced Dreamweaver CS6

CSS gives great power. But requires great responsibility.

Hypertext Markup Language, or HTML, is a markup

THE PRAGMATIC INTRO TO REACT. Clayton Anderson thebhwgroup.com WEB AND MOBILE APP DEVELOPMENT AUSTIN, TX

Financial. AngularJS. AngularJS.

HTML and CSS a further introduction

WINDEV 23 - WEBDEV 23 - WINDEV Mobile 23 Documentation version

Manual Html Image Src Url Path Not Working

Rails: MVC in action

Eggplant Functional Mykel Allen Bethel Tessema Bladimir Dominguez CSM Field Session 2018

An Introduction to JavaScript & Bootstrap Basic concept used in responsive website development Form Validation Creating templates

Ruby on Rails 3. Robert Crida Stuart Corbishley. Clue Technologies

BindTuning Installations Instructions, Setup Guide. Invent Setup Guide

Financial. AngularJS. AngularJS. Download Full Version :

Building beautiful websites with Bootstrap: A case study. by Michael Kennedy michaelckennedy.net

Table of Contents EVALUATION COPY

2017 Progress. All Rights Reserved. The Anatomy Of Responsive ASP.NET Apps WHITEPAPER

Creating and Publishing Faculty Webpages

PHP WITH ANGULAR CURRICULUM. What you will Be Able to Achieve During This Course

Contents. Managing Places...3. Contents 2

Manual Html A Href Onclick Submit Button

Responsive SharePoint WSP Edition

Transcription:

Lecture 7 Action View, Bootstrap & Deploying 1 / 40

Homeworks 5 & 6 Homework 5 was graded Homework 6 was due last night Any questions? 2 / 40

How would you rate the di culty of Homework 6? Vote at http://pollev.com/cis196776 3 / 40

Final Projects It's time to start thinking about your final project Proposals will be due on November 12 Ideas: Re-create one of your favorite sites Build off of one of the homeworks you started in this class More details to come next week 4 / 40

More Generators 5 / 40

More generators! These are the last generators that I will teach you There are plenty more, but these are enough for our purposes Model: rails g model model_name col1:type col2:type Scaffold: rails g scaffold model_name col1:type col2:type 6 / 40

Model Generator You pass the generator the name of the model and its attributes It creates the migrations and model file for you rails g model review course:references content:text 7 / 40

Sca old Generator Scaffolds made Rails famous Check out DHH's classic how to make a blog in 15 minutes video You pass the generator the name of the model and its attributes It creates: The migrations and model file The controller and views with RESTful routes The 7 RESTful routes in config/routes.rb rails g scaffold course code:string title:string 8 / 40

Action View 9 / 40

What does the View do? Handles data & communicates directly with the database Handles HTTP requests Displays content to the user Vote at http://pollev.com/cis196776 10 / 40

Using Action View in Rails It is Rails convention to place our views inside of the app/views/ directory Since views are associated with a controller, they'll be placed in a directory with the same name as the controller For our purposes, we will use files ending in.html.erb This allows us to embed ruby code directly in our views A view file for our traditional homepage might be placed inside of: app/views/welcome/index.html.erb 11 / 40

Which of the following will render the course's title to the screen? (In making this poll I discovered that Poll Everywhere uses Rails) A. <%= @course.title %> B. <% @course.title %> C. <%# @course.title %> Vote at http://pollev.com/cis196776 12 / 40

Layouts Can be used to extract out common boilerplate code Rails ships with a default layout: app/views/layouts/application.html.erb Every view that we create will be wrapped in this layout by default Contains <html>, <head>, <title>, <body> tags Our views will be placed inside of the <body> tags Uses <%= yield %> You can create other layouts (out of the scope of this class) 13 / 40

Partials Allow you to break your views into smaller chunks Great for small, reusable blocks of code They get placed into their own view file & can be rendered in other templates Names start with an _ Example: app/views/courses/_form.html.erb To render a partial in a template: <%= render 'courses/form' %> Notice the _ is omitted when rendering the partial 14 / 40

How can I pass data from the controller to the view? You can't You define a private method in the controller You define an instance variable in the controller action Vote at http://pollev.com/cis196776 15 / 40

Locals Partials should be modular Should not rely on instance variables passed from the controller Instead, they should use local variables that get passed along when the partial is rendered 16 / 40

Locals Example The courses form makes use of a course local variable <%# app/views/courses/_form.html.erb %> <%= form_with model: course do form %>... <% end %> The new controller action defines @course, so we pass it to the form when rendering it <%# app/views/courses/new.html.erb %>... <%= render 'form', course: @course %> 17 / 40

Action View Helpers Rails provides us with a number of helpers that can replace writing direct HTML For example: <%# app/views/layouts/application.html.erb %>... <%= stylesheet_link_tag 'application', media: 'all', 'data <%= javascript_include_tag 'application', 'data-turbolinks-tr... 18 / 40

URL Helper The URL helper provides us with some methods of interacting with URLs The most important one for our purposes is link_to link_to generates an anchor tag with the provided text and URL <%# The following are equivalent %> <%= link_to @course.name, @course %> <a href="/courses/<%= @course.id %>"><%= @course.name %></a> 19 / 40

link_to By default, the link_to helper will generate a link that makes a GET request We can pass along the method option to change the type of HTTP request <%= link_to 'Destroy', @course, method: :delete %> There are many options that we can pass to a link_to <%= link_to 'Courses', courses_path, class: 'link', id: 'course_link' %> 20 / 40

Form Helpers The Form helper provides us with some methods for interacting with forms We will focus on form_with (not form_tag or form_for) form_with generates the actual form while there are additional helpers for generating form fields 21 / 40

form_with We can pass it an object <%= form_with model: Course.new do form %> <%= form.text_field :title %> <% end %> <form action="/courses" method="post" data-remote="true"> <input type="text" name="course[title]"> </form> Or a URL <%= form_with url: courses_path do form %> <%= form.text_field :title %> <% end %> <form action="/courses" method="post" data-remote="true"> <input type="text" name="title"> </form> 22 / 40

Form Field Helpers We also get helpers to generate form fields Here are a few:... <%= form.label :title %> <%= form.text_field :title %> <%= form.text_area :description %> <%= form.check_box :complete %> <%= form.password_field :password %> <%= form.collection_select :notebook_id, Notebook.all, :id,... 23 / 40

Other Helpers There are a lot more Check out some of them here 24 / 40

Bootstrap 25 / 40

What is an HTML class? A collection of methods and attributes that can be used to instantiate an object An identifier that only one HTML element on a page can have An identifier that multiple HTML elements can have Vote at http://pollev.com/cis196776 26 / 40

Bootstrap We will be briefly cover Bootstrap 4 Allows us to quickly create web applications that look nice without having to write our own CSS Has a 12 column grid system that allows us to easily layout our site Basically just involves adding classes to our HTML elements 27 / 40

Bootstrap Pros & Cons Pros: Supported by almost every browser Mobile-first & extremely responsive Customizable Grid System Good documentation Cons: Very verbose, end up adding a ton of classes Without extensive customization, every Bootstrap site looks the same Tied to jquery Bit of a learning curve 28 / 40

Bootstrap Gem There are a number of ways to include Bootstrap in your project, we'll use the gem Thorough setup instructions are provided on the website The gem uses the Rails asset pipeline which makes it easy to customize Bootstrap and follow Rails best practices 29 / 40

Getting Started To add Bootstrap styling to our HTML, we add specific classes to different HTML elements I generally start by wrapping my content inside of a container <%# app/views/layouts/application.html.erb %>... <body> <div class="container"> <%= yield %> </div> </body>... 30 / 40

Navbar Next I usually add a Bootstrap-styled navbar to my app I create a partial for the navbar: app/views/layouts/_nav.html.erb Then I render the partial in the default layout: <%# app/views/layouts/application.html.erb %>... <body> <%= render 'layouts/nav' %> <div class="container"> <%= yield %> </div> </body>... 31 / 40

Tables Styling tables is a pretty straightforward task in Bootstrap For a very basic table, just requires adding the.table class to the <table> tag <table class="table"> <tr> <th>col 1</th> <th>col 2</th> </tr> <tr> <td>data A1</td> <td>data A2</td> </tr> </table> 32 / 40

Forms In Bootstrap, form styling goes on the form elements instead of the form itself <%= form_with model: @course do form %> <div class="form-group"> <%= form.label :title %> <%= form.text_field :title, class: 'form-control' %> </div> <%= form.submit class: 'btn btn-primary' %> <% end %> 33 / 40

Color You can also change text/background colors with some predefined color utility classes Primary: The app's primary color (blue by default) Secondary: The app's secondary color (gray by default) Success: Green by default Danger: Red by default Warning: Yellow by default Info: Teal by default Light, Dark, Muted, White 34 / 40

Size Used in different ways: For example, to specify the width of a button For example, to specify the intended behavior on a specific device size Sizes: xs, sm, md, lg, xl 35 / 40

Grid System Bootstrap uses a 12 column grid system (Bootstrap 4 also comes with flexbox) Can add sizes to the columns to specify how it should be displayed on certain device sizes <div class="container"> <div class="row"> <div class="col-2">col 1</div> <div class="col-6">col 2</div> <div class="col-4">col 3</div> </div> </div> 36 / 40

Possibilities of Bootstrap Bootstrap is very extensive and there's no way that I could go through it all Take a look at some of the examples Read through the documentation 37 / 40

Deploying 38 / 40

Heroku Heroku allows us to deploy our application to the web fairly easily and for no cost This guide does a great job of explaining the steps required to deploy an application 39 / 40

Homework 6 Part-2 Start as early as possible Part-2 starts with you copying over the required pieces from Part-1 Then, you'll Afterwards, you'll add in some Bootstrap styling and then deploy to Heroku Grading: Normal 25 points 5 manually graded points for deploying to Heroku & including Bootstrap 40 / 40