2013-07-29 41 views
0

我有一個搜索結果頁面,列出找到的項目。在該列表中,我有一個我想用來顯示結果縮略圖的按鈕。如何將現有集合傳遞給控制器​​以呈現頁面

我有控制器的方法,顯示搜索到的圖像:

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 

我得到這個呃ROR,這使我相信我得到例證ID數組作爲PARAMS [說明]:

undefined method `aws_image_thumbnail_url' for "2":String 

回答

0

link_to("Show", object)通常會產生一個URL像/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) 
相關問題