我在ruby on rails应用程序的一页上有一个表单,该表单需要通过文本输入字段输入用户。当用户单击“保存并继续”时,我希望下一页显示用户在上一页中输入的文本。
<div class="test-group">
<label class="test_label" for="full-name">
Enter full name
</label>
<form action="clientname" method="POST">
<input class = "test-input" type="text" name="name" id="client-name-entry">
<br/>
</form>
</div>
在通过“保存并继续”按钮访问的下一个链接页面上,我具有以下内容:
<div class="column-two-thirds">
<h1 class="test-label">Your name is <%= clientname %></h1>
<button type="submit" class="start-button" >Continue</button>
</div>
如何获取要显示在第二页上的名称,上面的内容给了我以下错误:
undefined local variable or method `clientname'
我知道我的application_controller中需要一些东西,但是我不确定那是什么。当前是:
def input_page
@client = clientname
end
我现在需要避免使用数据库,这就是为什么我试图仅使数据现在在页面之间持久保存的原因。
答案 0 :(得分:1)
持久性,没有数据库和服务器端,只能通过会话来完成。例如,提交第一页后,您可以执行以下操作:
session[:name] = params[:name]
,然后在下一页的表单中使用它:
<div class="column-two-thirds">
<h1 class="test-label">Your name is <%= session[:name] %></h1>
<button type="submit" class="start-button" >Continue</button>
</div>