返回顶部

收藏

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

标签:Ruby,Rails

收藏

0人收藏

支持

0

反对

0

»更多 您可能感兴趣的代码
  1. 2016-01-10 21:40:25Passing Data from an Action to a View by 胡晋
  2. 2016-08-20 16:38:38A loop executes the body of the loop by zetaliang
  3. 2016-08-20 16:54:59Escaping Sensitive Text by zetaliang
  4. 2016-10-10 09:35:27Initialize Data in an HTML Control by 永明
  5. 2016-08-20 17:12:28Tie a Text Field to a Model by JustForFly
  6. 2016-03-06 20:22:08Use cookie by digua
  7. 2016-03-21 10:38:51Call a Template File Directly by JustForFly
  8. 2016-08-20 17:33:13Creating a View by zetaliang
  9. 2016-08-20 17:50:56Selecting Which View to Render by LeoSun
  10. 2016-02-04 16:40:37Store Data in a Session by JustForFly
  11. 2016-09-02 20:39:30Creating the Application Framework: Putting Ruby on Rails by 永明
相关聚客文章
  1. 张映 发表 2013-01-31 16:33:11 centos ruby on rails apache mysql 安装配置详解
  2. sonataservice 发表 2013-07-04 09:17:04 [上海] 招 Ruby On Rails Developer 两枚
  3. hisea 发表 2013-07-25 16:32:48 [7.25]免费 Kindle 电子书: Ruby on Rails 4.0 Guide
  4. lan_chi 发表 2013-06-12 06:33:40 ruby2.x+rails4.x+puppet
  5. Alex Wood 发表 2014-12-10 17:20:18 Using Amazon RDS with Ruby on Rails and AWS OpsWor
  6. techug 发表 2014-12-30 15:35:42 你不可能有超过10年的Rails编程经验!
  7. 博主 发表 2011-09-16 16:44:00 Load Rails Environment with Ruby 1.9 Nearly as Fas
  8. Erick Guan 发表 2015-03-08 18:52:01 Ensuring the file uploaded by Refile
  9. viviworld 发表 2015-05-04 08:31:32 Ruby 和 Python
  10. jiyaping 发表 2011-04-09 00:00:00 搭建ruby on rails 环境
  11. 博主 发表 2005-11-04 08:00:00 many things inspired by ruby on rails
  12. 博主 发表 2012-09-23 00:00:00 Ruby On Rails环境搭建