Initialize data in an HTML Control
I'm having an issue with Initialize data in an HTML Control on page 151 - the HTML Control is not being Initialize with the data. Any suggestion?
Thanks
bnewton1
-------------------------
look_controller.rb
class LookController < ApplicationController
def at
@data_hash = params[:cruncher]
@cruncher = Cruncher.new(@data_hash[:crunch])
@data = @cruncher.crunch
end
def input
@cruncher = Cruncher.new("Steve")
end
end
cruncher.rb
class Cruncher
attr_reader :crunch
attr_writer :crunch
def initialize(data)
@crunch = data
end
end
input.rhtml
<!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">
<head>
<title>Using Text Fields</title>
</head>
<body>
<h1>Working With Text Fields</h1>
<p>This Ruby on Rails application lets you read data from text fields</p>
<%= start_form_tag ({:action => "at"}, {:method => "post"}) %>
<%= text_field ("cruncher","crunch", {"size" => 30}) %>
<br/>
<input type="submit" />
<%= end_form_tag %>
</body>
</html>
[b ] at.rhtml [/b]
<!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">
<head>
<title>Using HTML Control Shortcuts</title>
</head>
<body>
<h1>Using HTML Controls Shortcuts</h1>
<p>This application using Rails HTml Control shortcuts</p>
<p>Your Name is <%= @data %></p>
</body>
</html>
-----------------
|