Download presentation
Presentation is loading. Please wait.
Published byKeon Clarkin Modified over 9 years ago
1
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 1 Simple Rails Template <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> Hello, User This page was fetched at
2
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Rails Parameters The params hash contains the following values: :
3
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:
4
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 end @primes = [] candidate = 2 while @primes.length < count is_prime = true @primes.each do |prime| if (candidate % prime) == 0 then is_prime = false break end if is_prime then @primes << candidate end candidate += 1 end Query value determines # primes to compute Fill in @primes array with prime numbers
5
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 5 Template to Display Primes Prime Numbers The first prime numbers are: Prime Numbers ">
6
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
7
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 7 Layouts <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> app/views/layouts/application.html.erb: This page was fetched at app/views/rails_intro/hello.html.erb:
8
CS 140 Lecture Notes: File SystemsSlide 8
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.