">
Simple rails template
This presentation is the property of its rightful owner.
Sponsored Links
1 / 8

Simple Rails Template PowerPoint PPT Presentation


  • 34 Views
  • Uploaded on
  • Presentation posted in: General

Simple Rails Template. <?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"> <html xmlns ="http://www.w3.org/1999/xhtml" xml:lang ="en" lang ="en"> <head> <title>Hello, User</title>

Download Presentation

Simple Rails Template

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Simple rails template

Simple Rails Template

<?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">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"

lang="en">

<head>

<title>Hello, User</title>

</head>

<body>

<p>

This page was fetched at <%= Time.now() %>

</p>

</body>

</html>

CS 142 Lecture Notes: Rails Controllers and Views


Control structures in templates

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">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>Rails Parameters</title>

</head>

<body>

<p>

The <code>params</code> hash contains the

following values:

</p>

<% params.each do |key, value| %>

<p><%= key %>: <%= value%></p>

<% end %>

</body>

</html>

CS 142 Lecture Notes: Rails Controllers and Views


Control structures cont d

Control Structures, cont’d

Template:

...

<% params.each do |key, value| %>

<p><%= key %>: <%= value%></p>

<% end %>

...

HTML:

...

<p>x: 44</p>

<p>y: 92</p>

<p>action: showParams</p>

<p>controller: rails_intro</p>

...

CS 142 Lecture Notes: Rails Controllers and Views


Controller compute primes

Controller: Compute Primes

classRailsIntroController < ApplicationController

defshow_primes

ifparams[:count] != nil then

count = params[:count].to_i()

else

count = 10

end

@primes = []

candidate = 2

while@primes.length < count

is_prime= true

@primes.eachdo |prime|

if(candidate % prime) == 0 then

is_prime= false

break

end

end

ifis_primethen

@primes << candidate

end

candidate += 1

end

end

end

Query value determines# primes to compute

Fill in @primes arraywith prime numbers

CS 142 Lecture Notes: Rails Controllers and Views


Template to display primes

Template to Display Primes

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE ...>

<html ...>

<head>

<title><%= @primes.length %> Prime Numbers</title>

<%= stylesheet_link_tag 'main' %>

</head>

<body>

<p>

The first <%= @primes.length %> prime numbers are:

</p>

<table class="oddEven" cellspacing="0">

<tr class="header"><td>Prime Numbers</td></tr>

<% @primes.each do |prime| %>

<tr class="<%=cycle('odd', 'even')%>">

<td><%=prime%></td>

</tr>

<% end %>

</table>

</body>

</html>

CS 142 Lecture Notes: Rails Controllers and Views


Directory structure

Directory Structure

app

controllers

rails_intro_controller.rb

student_controller.rb

views

rails_intro

hello.html.erb

show_params.html.erb

show_primes.html.erb

student

models

assets

images

javascripts

stylesheets

application.css

db

migrate

CS 142 Lecture Notes: Rails Controllers and Views


Layouts

Layouts

app/views/layouts/application.html.erb:

<?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">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"

lang="en">

<head>

<title><%=@title %></title>

</head>

<body>

<%= yield %>

</body>

</html>

app/views/rails_intro/hello.html.erb:

<% @title = "Hello, user" %>

<p>

This page was fetched at <%= Time.now() %>

</p>

CS 142 Lecture Notes: Rails Controllers and Views


Simple rails template

CS 140 Lecture Notes: File Systems


  • Login