每个人,我都是将我的搜索结果重定向到一个高级搜索表单,其中包含使用ransack gem的更多过滤器。当我点击搜索按钮时,它会转到我的'search_path',但不会显示任何结果 我的控制台日志打印此sql查询
SELECT "listings".* FROM "listings" WHERE ( status <> NULL AND town = 'milan') LIMIT $1 OFFSET $2 [["LIMIT", 15], ["OFFSET", 0]]
我不明白为什么状态&lt;&gt;空值。我期待状态[:pending]
但高级搜索工作非常精细。我的索引页面上的简单表单
def search
@param_s = params[:search]
if @param_s && @param_s != ""
@listing_search = Listing.includes(:photos).where(" status <> ? AND town = ?",Listing.statuses[:pendeng], @param_s).page( params[:page]).per(4)
else
@listing_search = Listing.includes(:photos).pending.page( params[:page]).per(20)
end
@search = @listing_search.ransack(params[:q])
@listing = @search.result.page( params[:page]).per(15)
@arrlisting = @listing.to_a
end
<%= form_tag search_path, method: :get do %>
<%= text_field_tag :search, params[:search] %>
<%end%>
<%= search_form_for @search, url: search_path,remote: true do |f| %>
<%= f.select :home_type_cont,[["Apartment","apartment"],["Flat","flat"],["Hostel","hostel"],["Room","room"],["Business","business"]],{:include_blank => 'Select....'} %>
<%= f.select :bed_room_gteq,[["1",1],["2",2],["3",3],["4 +",4]]%>
----more-- filters
<%end%>
class Listing < ApplicationRecord
enum status: [:pending, :rejected, :approved ]
belongs_to :user
has_many :photos, dependent: :destroy
validates :listing_name, presence: true
validates :town, presence: true
validates :home_type, presence: true
end
答案 0 :(得分:0)
您有一个拼写错误Listing.statuses[:pendeng]
,它应该是Listing.statuses[:pending]
,所以这就是它返回nil
而不是正确值的原因。
此外,您似乎已经拥有pending
的范围:
Listing.includes(:photos).pending.where(town: params[:search])