Ruby on rails Can';t链接到属于某个类别的对象

Ruby on rails Can';t链接到属于某个类别的对象,ruby-on-rails,ruby-on-rails-3,relationship,rails-activerecord,Ruby On Rails,Ruby On Rails 3,Relationship,Rails Activerecord,我有一种方法,可以将我所有的书分类在一起 def self.categories_list joins(:books). select('categories.id, categories.name, count(*) AS books_count'). group('categories.id, categories.name'). order('books_count DESC') end 然后我可以像这样将它们输出到我的视图中 @bookcategories = Category.cat

我有一种方法,可以将我所有的书分类在一起

def self.categories_list
joins(:books).
select('categories.id, categories.name, count(*) AS books_count').
group('categories.id, categories.name').
order('books_count DESC')
end
然后我可以像这样将它们输出到我的视图中

@bookcategories = Category.categories_list
然后我想做的是通过点击视图中的“计算”链接到所有属于“计算”的书籍

<% @bookcategories.each do |b| %>
  <li><%= link_to b.name, category_path(b.name) %></li>
<% end %>
以及显示动作的视图

  <div class="container">
   <div class="row ">
    <div class="span12">     
     <% @categorisedbooks.each do |c| %>
      <%= image_tag c.avatar.url(:medium), :class=> "allBooksCover" %>
     <% end %>
   </div>
  </div>
 </div>
参数被传递为

  Parameters:{"id"=>"Computing"}

因此,您需要在
中显示
操作

@category = Category.where(:name => params[:id]).first
# etc

你的玩笑。。。不敢相信我没有这么做,所以它的名称(类别名称)匹配的图书id
  Parameters:{"id"=>"Computing"}
@category = Category.where(:name => params[:id]).first
# etc