载波:拇指参数个数错误 [英] carrierwave :thumb wrong number of arguments

查看:56
本文介绍了载波:拇指参数个数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与Ryan Bates的载波Wave Railscast一起关注 http:// railscasts。 com / episodes / 253-carrierwave-file-uploads 。有一次,在将图像调整为缩略图大小后,他显示带有以下代码的缩略图

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 %>

我在profilepic实例变量上调用url方法,并尝试获取这样的缩略图

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 %>

但是我得到了错误

wrong number of arguments (1 for 0)

:thumb参数。

It's not expecting the :thumb parameter.

在image_uploader中,我安排了这样的缩略图创建(安装了rmagick之后)

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

有人可以解释我在做什么错吗?我发现了一个关于主题 Rails:image_tag问题的问题,该问题说明了该参数(在case:thumb)需要传递给对象(而不是对象本身)的url方法。这就是我正在做的,但我遇到了错误。

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.

推荐答案

首先,来自Ryan的代码有错字

First, the code from Ryan have a typo

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

正确的是

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

此内容已在该esp的评论中发布。

This already posted in the comment of that esp.

对于您的代码,@profilepic是模型或载波的obj

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

例如@profilepic = ProfilePic.find:first
@ profilepic.url只是ProfilePic中的一种方法

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

调用载波控制文件url的正确语法是
@ profilepic.image.url(:thumb)

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

希望这不要太令人困惑。

Hope this not too confusing.

这篇关于载波:拇指参数个数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆