在rails helper中使用时,Carrierwave asset_path成为未定义的方法

时间:2017-06-12 04:06:30

标签: ruby-on-rails carrierwave

Rails 5.1.1, 红宝石2.2.5p319, Carrierwave 1.1.0

尝试重构一个视图片段,将整个应用程序重用到一个帮助器中,然后我就撞墙了。问题模型上有两个载波上传器:Image和Imageback。我正在将变量传递给方法,以确定我想要命中哪一列(在下面的代码中作为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 个答案:

没有答案