0
我有一個網站,用戶可以根據國家,價格,季節和組織者搜索運動營目錄。看起來是這樣的:在Rails中單擊圖片時搜索
當用戶點擊搜索我得到'的搜索頁面,並在其中的網址,然後呈現運動陣營匹配搜索PARAMS的列表中添加PARAMS。這工作完美無瑕。該URL看起來像這樣: "localhost:3000/camps?utf8=✓&country=Spain&organiser=Brett&season=Summer&price=5000&commit=Search"
進一步向下的頁面我有一個圖像列表與最流行的國家,例如「西班牙」。我的問題是這樣的:
如何添加一個鏈接到圖像,然後搜索所有陣營與國家=西班牙?
型號:
class Camp < ApplicationRecord
def self.search(country, price, organiser, season)
where("country LIKE ? AND price < ? AND organiser LIKE ? AND season LIKE ?", country, price, organiser, season)
end
end
控制器:
def search
country = params[:country]
price = params[:price]
organiser = params[:organiser]
season = params[:season]
if country.blank?
country = '%'
end
if season.blank?
season = '%'
end
if organiser.blank?
organiser = '%'
end
@camps = Camp.search(country, price, organiser, season)
end
HTML:
<div class="col-md-4">
<%= link_to image_tag("cardheader.png") %>
</div>
THX爲你的回覆。當這樣做時,我的網址變成:[http:// localhost:3000/camps?country = spain],理想情況下應該是[/ camps?utf8 =✓&country = Spain&organizer =&season =&price =&commit = Search] 這樣做並不會產生任何結果。 – Andy
因此您在發送時還需要所有其他參數? – Sravan
似乎是這樣的情況。或者,我可以在具有特定國家/地區搜索的模型中創建新控制器和新功能。 – Andy