Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > BOOK: Beginning Ruby on Rails
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Ruby on Rails
This is the forum to discuss the Wrox book Beginning Ruby on Rails by Steve Holzner Ph.D.; ISBN: 9780470069158
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Ruby on Rails section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 27th, 2009, 01:20 PM
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 5 - Tying controls to models

Had some issues to get this of the ground with the new version of ROR. And tried to find the solution in here - no luck.

But here is a solution that work as supposed.

---- look_controller.rb ----
Code:
class LookController < ApplicationController
  def at
    @data_hash = params[:cruncher]
    @cruncher = Cruncher.new(@data_hash[:crunch])

    @data = @cruncher.crunch
  end

  def input
    @cruncher = Cruncher.new("")
  end
end
---- cruncher.rb ----
Code:
class Cruncher 
  attr_reader :crunch
  attr_writer :crunch

  def initialize(data)
    @crunch = data
  end

end
---- at.rhtml ----
Code:
<html>
  <head>
    <title>Using HTML Control Shortcuts</title>
  </head>

  <body>
    <h1>Using HTML Control Shortcuts</h1>
    This application uses Rails HTML control shortcuts.
    <br>
    <br>
    Your name is <%= @data %>.
    <br>
    <br>
  </body>
</html>
---- input.rhtml ----
Code:
<html>
  <head>
    <title>Using Text Fields</title>
  </head>
  <body>
    <h1>Working With Text Fields</h1>
    This Ruby on Rails application lets you read data from text fields.
    <br>
    <%= form_tag ({:action => "at", :method => "post"}) %>
      Please enter your name.
      <br>
      <%= text_field ("cruncher", "crunch", {"size" => 30}) %>
      <br>
      <br>
      <input type="submit"/>
    <%= form_tag %>
  </body>
</html>
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap. 5, Confusion: Tying Controls to Models mprogers BOOK: Beginning Ruby on Rails 3 December 12th, 2008 03:13 AM
Report Builder Models? SQLScott Reporting Services 2 October 26th, 2007 02:34 PM
Problem accessing Simulink models from C# karveajit C# 1 July 14th, 2006 01:55 AM
tying in animation to music nancy Flash (all versions) 0 May 31st, 2005 02:35 PM
Big models question darrinps BOOK: Expert One-on-One J2EE Design and Development 0 June 4th, 2003 03:10 PM



All times are GMT -4. The time now is 04:59 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.