2012-05-24 36 views
0

我試圖找到與當前查看記錄具有類似標籤的所有記錄。 我的控制器具有:奇怪的行爲與acts_as_taggable_on的tagged_with方法

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

(如果積分誰能告訴我如何在隨機的arrary記錄的順序) 我的觀點只是遍歷數組。

無論如何,它的工作原理幾乎所有的時間,但我注意到它打破偶爾進行故障診斷時,我發現,當我使用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

我猜你是路徑幫手問題:

member_tattoo_path(t.member, t) 

我在錯誤的描述看到

:member_id=>nil 

因此,原來文身標記與耶西Smith還沒有相應的公司章程名稱'member'和需要有效id的路徑助手會拋出異常。

+0

哦,你知道嗎?我很愚蠢,我應該看到這一點,並意識到我沒有在該視圖中包含if/else語句,我認爲該休息了。謝謝! – rugbert