Language Ruby on Rails
(It's all in the View)
| Date: | 08/15/09 |
| Author: | bjelli |
| URL: | n/a |
| Comments: | 0 |
| Info: | http://guides.rails.info/ |
| Score: |
# Ruby on Rails is a Framework for Web Applications.
# it follows the model - view - controller pattern.
# One Application has to consist of several files
#
# You can find the whole source on github:
# http://github.com/bjelline/bottle/tree/master
# and test the application on heroku
# http://bottles.heroku.com/
------------------ config/routes.rb -------------------
# in this file the mapping from URL to controller is defined
ActionController::Routing::Routes.draw do |map|
map.root :controller => "wall"
map.resources :wall, :singular => :wall_instance
end
------------------ app/controller/wall.rb -------------------
class WallController < ApplicationController
def show
@i = params[:id].to_i
end
end
------------------ app/views/wall/index.html.erb -------------
<p><%= link_to "Sing the song", :controller => :wall, :action => :show, :id => 99 %></p>
------------------ app/views/wall/show.html.erb -------------
<%
while @i > 0 do
%>
<p>
<%= say_bottles(@i) %> of beer on the wall,
<%= say_bottles(@i) %> of beer.
<br />
<%
@i = @i - 1
%>
Take one down and pass it around,
<%= say_bottles(@i) %> of beer on the wall.
</p>
<%
end
%>
<p>No more bottles of beer on the wall, no more bottles of beer. <br />
Go to the store and buy some more, 99 bottles of beer on the wall.</p>
------------------ app/helpers/wall/application_helper.rb -------------
module ApplicationHelper
def say_bottles( count )
case @i
when 0
"No more bottles"
when 1
"One bottle"
else
"#{count} bottles"
end
end
end
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments