Read Data from a Text Field : Form TextField « Rails « Ruby






Read Data from a Text Field


File: public\input.html, adding this 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 action = "/hello/there" >
       Please enter your name.
       <br>
       <input type="text" name="text1">
       <br>
       <br>
       <input type="submit"/>
     </form>
   </body>
 </html>

File: app\controllers\hello_controller.rb:

 class HelloController < ApplicationController
   def there
     @data = params[:text1]
   end
 end

File: app\views\hello\there.rhtml:

 <html>
   <head>
     <title>Reading data from text fields</title>
   </head>
   <body>
     <h1>Reading data from text fields</h1>
     This Ruby on Rails application reads data from text fields.
     <br>
     <br>
     Your name is <%= @data %>.
     <br>
     <br>
   </body>
  </html>
  
  
 Start the WEBrick server: ruby script/server
 Navigate to http://localhost:3000/input.html

 

 








readTextField.zip( 89 k)

Related examples in the same category