1
我必须在网站的主页上修改搜索。代码用Ruby语言编写,并使用“Rails”框架工作。Ruby on Rails多个搜索查询
***图片******
这里,已经是与邮件ID搜索的选项。但也有一个id字段。需要实施多重搜索。
“视图”(MVC架构)已经编写的代码: -
<form action="https://stackoverflow.com/users/search" method="POST">
<label for="email">Email</label>
<input type="text" name="email" />
<input type="submit" name="search" value="Search" />
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
</form>
的 “控制器” 已经编写的代码(MVC架构): -
def search
@users = User.paginate(
:conditions => ["email LIKE ?", '%' + params[:email] + '%'],
:page => params[:page], :per_page => 25,
:order => params[:order].nil? ?
:email : params[:order].gsub('-', ' ')
)
if @users.length == 1
redirect_to edit_user_path(@users.first)
else
render "index"
end
end
请帮助我到在控制器文件中使用条件为的多重搜索满足以下条件: -
搜索与ID
- 搜索与电子邮件(已写入)
- 搜索与电子邮件和ID
谢谢Bachan Smruty :) – Monisha