Ruby on rails 在RubyonRails中单击搜索按钮后获取文本字段值和页面后的搜索结果
在我的搜索页面中,我有一个邮政编码的文本字段,当我在文本字段中输入邮政编码并单击搜索按钮时,文本字段的值为loss,搜索结果也为loss,单击搜索按钮后,我如何稳定邮政编码的文本字段值和搜索结果。以下是我的查看页面:Ruby on rails 在RubyonRails中单击搜索按钮后获取文本字段值和页面后的搜索结果,ruby-on-rails,Ruby On Rails,在我的搜索页面中,我有一个邮政编码的文本字段,当我在文本字段中输入邮政编码并单击搜索按钮时,文本字段的值为loss,搜索结果也为loss,单击搜索按钮后,我如何稳定邮政编码的文本字段值和搜索结果。以下是我的查看页面: <%= form_for :search, :url => { :method => :get, :action => :search } do |f| %> <table width="100%"> <tr>
<%= form_for :search, :url => { :method => :get, :action => :search } do |f| %>
<table width="100%">
<tr>
<td align="center" style="vertical-align:top;" width="35%">
<table>
<tr>
<td align="center">
<%= text_field_tag "tf_Zip",nil,:placeholder =>'Zip' %>
</td>
</tr>
</table>
<table>
<% if !@user.nil? %>
<% @user.each do |uzr| %>
<tr>
<td bgcolor="#CCDBE0" width="40%">
<%= image_tag @user_img.photo.url(:small),:alt => " " %>
<br/>
<div><a style="color:blue;" href = 'profile?id=<%= uzr.id %>'><%= uzr.First_Name + " " + uzr.Last_Name %></a></div>
</td>
<td bgcolor="#CCDBE0" width="60%" style="text-align:center;">
<div class='buttonblck1'><a href='searchings?id=<%= uzr.id %>'>Send Request </a></div>
</td>
</tr>
<% end %>
<% end %>
</table>
<% end %>
请建议我,等待你的答复。”
首先谢谢你:
form\u for
用于ActiveModel
或ActiveRecord
的实例如果要创建不基于对象的表单,请使用
form\u标记
第二:
由于没有存储属性的对象,您必须自己提供它们。
该值在text\u field\u标记的第二个参数中定义
i、 e.在控制器中:
@zip_search = params[:tf_Zip].presence
if @zip_search
@user = ...
end
在你看来:
<%= form_tag url_for( :controller => :search, :action => :search), :method => :get) do %>
<%= text_field_tag "tf_Zip", @zip_search, :placholder => 'Zip' %>
<% end %>
:搜索,:操作=>:搜索),:方法=>:获取)执行%>
'Zip'>
<%= form_tag url_for( :controller => :search, :action => :search), :method => :get) do %>
<%= text_field_tag "tf_Zip", @zip_search, :placholder => 'Zip' %>
<% end %>