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