我试图找到与当前查看的记录具有相似标签的所有记录。 我的控制器有:
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)
时它会有效
所以每个词都有一个空格但是无论出于何种原因'jesse smith'杀死了这个动作。
我的控制台显示我也有路由错误:
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'
那么为什么一个术语导致路由错误而不是其他术语?
答案 0 :(得分:0)
我猜你的路径助手有问题:
member_tattoo_path(t.member, t)
我在你的错误描述中看到了
:member_id=>nil
事实证明,用jesse smith标记的纹身与名称'member'没有对应的关联,而需要有效id的路径助手则抛出异常。