CS 142 Lecture Notes: Rails Controllers and ViewsSlide 1 Simple Rails Template <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" xml:lang="en" lang="en"> Hello, User This page was fetched at
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 2 Control Structures in Templates ?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " Rails Parameters The params hash contains the following values: :
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 3 Control Structures, cont’d... :... :... x: 44 y: 92 action: showParams controller: rails_intro... x: 44 y: 92 action: showParams controller: rails_intro... Template: HTML:
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 4 Controller: Compute Primes class RailsIntroController < ApplicationController def show_primes if params[:count] != nil then count = params[:count].to_i() else count = 10 = [] candidate = 2 < count is_prime = do |prime| if (candidate % prime) == 0 then is_prime = false break end if is_prime << candidate end candidate += 1 end Query value determines # primes to compute Fill array with prime numbers
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 5 Template to Display Primes Prime Numbers The first prime numbers are: Prime Numbers ">
Directory Structure CS 142 Lecture Notes: Rails Controllers and ViewsSlide 6 app rails_intro views models controllers rails_intro_controller.rb student_controller.rb hello.html.erb show_params.html.erb show_primes.html.erb student stylesheets main.css db migrate assets javascripts images
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 7 Layouts <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" xml:lang="en" lang="en"> app/views/layouts/application.html.erb: This page was fetched at app/views/rails_intro/hello.html.erb:
CS 140 Lecture Notes: File SystemsSlide 8