0

我试图找到与当前查看的记录具有相似标签的所有记录。我的控制器有:

  def show
    @tattoo =Tattoo.find(params[:id])
    tags = @tattoo.style_list.join(", ")
    @tattoos = Tattoo.tagged_with(tags, :any => true).limit(6)
  end

(如果有人能告诉我如何随机化数组中记录的顺序,则加分)我的视图只是循环遍历数组。

无论如何,它几乎一直有效,但我注意到它偶尔会中断,在故障排除时我发现它在我使用时会中断,tagged_with("jesse smith", :any => true)但在我尝试tagged_with("jason stephan", :any => true)tagged_with("black ink", :any => true)

所以每个术语都有一个空格,但无论出于何种原因,“杰西史密斯”都会扼杀行动。

我的控制台显示我也有路由错误:

ActionView::Template::Error (No route matches {:action=>"show", :controller=>"tattoos", :member_id=>nil, :id=>#<Tattoo id: 170, description: "", status: "approved", member_id: nil, created_at: "2011-10-25 23:08:17", updated_at: "2011-11-17 16:56:55", file_file_name: "starry-eyed-rabid-squirrelweb.jpg", file_content_type: "image/jpeg", file_file_size: 294782, file_updated_at: "2011-10-25 23:08:17", album_id: nil, position: 116, favorite_count: 0, share_count: 1, file_remote_url: "http://www.jessesmithtattoos.com/wp-content/gallery...">}):
    22:    <ol class="small_tattoos">
    23:     <% @tattoos.each do |t| %>
    24:       <li>
    25:       <%= link_to image_tag(t.file.url(:tiny),:alt=>"#{t.style_list}, rtattoos, tattoos"), member_tattoo_path(t.member, t) %>
    26:       </li>
    27:     <% end %>
    28:    </ol>
  app/views/index/show.html.erb:25:in `block (2 levels) in _app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'
  app/views/index/show.html.erb:23:in `block in _app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'
  app/views/index/show.html.erb:11:in `_app_views_index_show_html_erb___1839804211534816245_69842632179360__4333294961394575926'

那么为什么一个术语会导致路由错误而不是其他术语呢?

4

1 回答 1

0

我猜你对路径助手有问题:

member_tattoo_path(t.member, t)

我在您的错误描述中看到

:member_id=>nil

所以原来用 jesse smith 标记的纹身与名称“成员”没有对应的关联,并且需要有效 id 的路径助手抛出异常。

于 2012-05-24T02:42:53.690 回答