2017-06-12 52 views
0

的Rails 5.1.1, 紅寶石2.2.5p319, Carrierwave 1.1.0Carrierwave asset_path成爲導軌輔助使用時未定義的方法

試圖重構的是,得到重用所有懸停在應用到輔助的圖片我正在撞牆。問題模型中有兩個載波上傳器:Image和Imageback。我傳遞變量的方法,以確定我試圖打

Helper方法(如下面的代碼graphic通過)(在application_helper.rb)的列:

def issue_image_display(issue, graphic, size, sizeinpx, lodge = nil) 
    if graphic 
    if graphic == "imageback" 
     link_to image_tag(issue.imageback_url(size)), 
     imageback_url(:full), rel: :lazybox 
    else 
     link_to image_tag(issue.image_url(size)), 
     image_url(:full), rel: :lazybox 
    end 
    else 
    image_tag(
     "missing_flap.jpg", 
     alt: "No Flap Image for #{issue.combined}", 
     style: "width: #{sizeinpx}px" 
    ) 
    end 
end 

這是通過調用以下:

<ul class="issue-list" id="issues"> 
    <div class="page"> 
    <%# cache issue do %> 
     <%= render partial: "issues/issue_small", 
       collection: @issues, 
       as: :issue, 
       wishlist: false, 
       locals: { 
       size: :list, 
       sizeinpx: '200' 
       } %> 
    <%# end %> 
    </div> 
</ul> 

並且局部被遍歷,調用實際的輔助方法:

<li class="issue-container"> 
    <article class="issue"> 
    <%= issue_image_display(issue, issue.image, size, sizeinpx) %> 
    <p class="lodge-name"> 
     <%= link_to issue.combined, lodge_issue_path(issue.lodge, issue) %> 
     <span><%= issue.first_issue.stamp("1969") if issue.first_issue %> | (OA BBv6: <%= issue.oa_bb_combined %>)</span> 
    </p> 
    <% if :wishlist == true -%> 
    <p class="add-to-wishlist"> 
     <%= link_to 'Add to Wishlist', wishlist_items_path(issue_id: issue.id), method: :post, class: "button button-small" %> 
    </p> 
    <% end -%> 
    </article> 
</li> 

錯誤是:

ActionView::Template::Error at /issues 
undefined method `asset_path' for #<ImageUploader::Uploader70194310458580:0x007faec5409400> 
+0

你在哪一行代碼中得到那個錯誤? – Pavan

+0

它調用它作爲文件的第16行調用部分,當包括我修剪的其他東西是:'<%= render partial:「issues/issue_small」,' –

回答

0

原來有上述兩種故障。 ActionView掩蓋了它們,所以我一直拉它,直到我得到一個有意義的行號。

if graphic 
    if graphic == "imageback" 
     link_to image_tag(issue.imageback_url(size)), 
     imageback_url(:full), rel: :lazybox 
    else 
     link_to image_tag(issue.image_url(size)), 
     image_url(:full), rel: :lazybox 
    end 
    else 

失蹤的issue呼叫image_url之前,所以它被調用沒什麼carrierwave方法。

第二個問題是if graphic檢查。結果總是這樣寫的。要通過它,它需要成爲if !graphic.blank?。這是次要的實際錯誤,但爲任何人在未來遇到這種奇怪的情況記錄它。

相關問題