【发布时间】:2014-08-12 19:39:49
【问题描述】:
我需要保存从用户那里获取的输入,但我发现了一个以错误和旧格式工作的代码,
文件:public\input.html,添加这段代码:
<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>
文件:app\controllers\hello_controller.rb:
class HelloController < ApplicationController
def there
@data = params[:text1]
end
end
文件: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
那是代码 sn-p,老实说,它就像一个魅力,但在当前的 rails api 中它给了我这样的东西:
<!--
<form action = "home/omg" >
<%= label_tag(:text1, "Enter the message:") %>
<%= text_field_tag :text1 %>
<%= submit_tag"submit" %>
-->
那么有什么区别以及如何使用给定的输入,
我想要并且需要的是当用户单击按钮时 - 提交按钮 - 获取文本字段中的文本并将其用作我的家庭控制器中的字符串。我怎样才能做到这一点?
【问题讨论】:
标签: jquery ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4