File: controllers\hello_controller.rb
class HelloController < ApplicationController
def there
@data_hash = params[:cruncher]
@cruncher = Cruncher.new(@data_hash[:crunch])
@data = @cruncher.crunch
end
def input
@cruncher = Cruncher.new("AAA")
end
end
File: app\models\cruncher.rb
class Cruncher
attr_reader :crunch
attr_writer :crunch
def initialize(data)
@crunch = data
end
end
File: app\views\hello\input.rhtml
Using Text Fields
Working With Text Fields
This Ruby on Rails application lets you read data from text fields.
<%= form_tag ({:action => "there"}, {:method => "post"}) %>
Please enter your name.
<%= text_field ("cruncher", "crunch", {"size" => 30}) %>
<%= form_tag %>
File: app\views\hello\there.rhtml
Using HTML Control Shortcuts
Using HTML Control Shortcuts
This application uses Rails HTML control shortcuts.
Your name is <%= @data %>.
Start the WEBrick server: ruby script/server
http://localhost:3000/hello/input
initializeDataHTMLControl.zip( 93 k)