我有一個顯示3個搜索結果列表的頁面:插圖,小說和標籤。我想允許用戶單擊每個列表的鏈接以查看縮略圖網格。我無法理解如何將搜索結果對象傳遞到新頁面。我只是得到插圖id的字符串。鏈接到不同的搜索結果視圖
main_controller的搜索方法,以及我想要做show_illustrations:
def search
@search_criteria = params[:search]
@novels = Novel.search(params[:search])
@illustrations = Illustration.search(params[:search])
@tags = Tag.search(params[:search])
respond_to do |format|
format.html #search_results.html.erb
end
end
def show_illustrations
@illustrations = params[:illustrations]
end
,顯示在搜索結果中的插圖列表中的部分。該應用程序調用上的主要展示方法堅持即使我給你在的link_to聲明的行動,以「show_illustrations」:
<% if @illustrations.size() > 0 %>
<div class="row-fluid">
<div class="span8">
<h3>Illustrations</h3>
</div>
<div class="span4">
<%= link_to "View", {:controller => "main", :action => "show_illustrations", :illustrations => @illustrations}, :class => "btn btn-mini"%>
</div></div>
<div class="search_results well-search-results">
<table class="table table-striped table-condensed">
<% @illustrations.each do |illustration| %>
<tr>
<td><%= illustration.name %></td>
<td><%= link_to "Show", illustration, :class => "btn btn-primary btn-mini", :style => "float:right;" %></td>
</tr>
<% end %>
</table>
</div>
<% else %>
<h3>No Matching Illustrations</h3>
<% end %>
應該表現出圖文並茂的網格中的頁面,標題爲searched_illustrations.html.erb:
<div class="container">
<div class="well padding:0px;">
<% @illustrations.each_slice(4) do |set| %>
<div class="row-fluid">
<% set.each do |illustration| %>
<div class="span3">
<div style="text-align:center"><%= link_to image_tag(illustration.image_thumbnail_url), illustration %>
<br />
<%= illustration.name %><br />
<%= link_to illustration.novel.name, illustration.novel %> -
<%= illustration.novel.edition %>
<% if ! illustration.tags.empty? %>
<br />
<% illustration.tags.each do |tag| %>
<%= tag %>
<% end %>
<% end %>
</div>
<br />
</div>
<% end %>
</div>
<br \>
<% end %>
</div>
</div>
的routes.rb:
match 'main/show_illustrations' => 'main#show_illustrations', as: :show_illustrations