我有一个搜索结果页面,列出了找到的项目。在该列表中,我有一个按钮,我想用它来显示结果的缩略图。
我有控制器方法显示搜索到的图像:
def search
@search_criteria = params[:search]
@novels = Novel.where("lower(name) like ?", "%#{@search_criteria.downcase}%")
@novels.sort! { |a,b| a.name.downcase <=> b.name.downcase }
@searched_illustrations = Illustration.where("lower(name) like ?", "%#{@search_criteria.downcase}%")
@tagged_illustrations = Illustration.tagged_with([@search_criteria], :any => true, :wild => true)
@illustrations = @searched_illustrations + @tagged_illustrations
@illustrations.uniq!
@illustrations.sort! { |a,b| a.name.downcase <=> b.name.downcase }
respond_to do |format|
format.html #search_results.html.erb
end
end
以下是我附加到视图上显示搜索结果的按钮的代码:
<%= link_to "Show", illustration, :class => "btn btn-custom-primary btn-mini", :style => "float:right;" %>
以下是我必须显示缩略图的控制器方法:
def show_illustrations
@illustrations = params[:illustrations]
@illustrations = Kaminari.paginate_array(@illustrations).page(params[:page]).per(20)
respond_to do |format|
format.html #search_results.html.erb
end
end
我收到了这个错误,这让我相信我得到了一系列插图ID作为参数[插图]:
undefined method `aws_image_thumbnail_url' for "2":String
答案 0 :(得分:0)
link_to("Show", object)
通常会生成/illustrations/:id
之类的网址。一条秀路线。你正在尝试渲染一个集合。
一般来说,我认为您只是想以不同的方式显示搜索结果,不是吗?至少这是我从你的例子中收集到的。如果是这种情况,请渲染不同的视图。
def search
# search stuff... (you should try ElasticSearch/Tire)
#
# Now, use a different template if the 'thumbs' param is present
return render :search_thumbs unless params[:thumbs].nil?
end
在视图中:
= link_to "View Thumbs", search_path(search: params[:search], thumbs: true)