carrierwave :thumb wrong number of arguments

大城市里の小女人 提交于 2019-12-08 04:37:57

问题


I'm following along with Ryan Bates' carrierwave Railscast http://railscasts.com/episodes/253-carrierwave-file-uploads. At one point, after resizing the images into a thumbnail, he displays the thumbnail with the following code

  <%=  image_tag painting.image_url(:thumb).to_s %>

I'm calling the url method on the profilepic instance variable and trying to get the thumbnail like this

 <%=  image_tag @profilepic.url(:thumb).to_s %>

But I get the error

wrong number of arguments (1 for 0)

It's not expecting the :thumb parameter.

In the image_uploader, I arranged for the thumbnail to be created like this (after installing rmagick)

 version :thumb do
    process :resize_to_limit => [50, 50]
  end

Can anyone explain what I might be doing wrong? I found an SO question on topic Rails: image_tag issue, which explains that the parameter (in this case :thumb) needs to be passed to the url method on the object (and not the object itself). That's what I'm doing, but I'm getting the error.


回答1:


First, the code from Ryan have a typo

<%=  image_tag painting.image_url(:thumb).to_s %>

the correct one is

<%=  image_tag painting.image.url(:thumb).to_s %>

This already posted in the comment of that esp.

For your code, the @profilepic is a obj from model or from carrierwave

e.g. @profilepic = ProfilePic.find :first @profilepic.url is just a method from ProfilePic

The correct syntax for call the url of carrierwave control file is @profilepic.image.url(:thumb)

Hope this not too confusing.



来源:https://stackoverflow.com/questions/16228347/carrierwave-thumb-wrong-number-of-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!