Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > BOOK: Beginning Ruby on Rails
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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>





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 01:34 PM
Problem accessing Simulink models from C# karveajit C# 1 July 14th, 2006 12:55 AM
tying in animation to music nancy Flash (all versions) 0 May 31st, 2005 01:35 PM
Big models question darrinps BOOK: Expert One-on-One J2EE Design and Development 0 June 4th, 2003 02:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.