回形针的导轨问题

发布于 2024-12-08 13:17:49 字数 566 浏览 0 评论 0原文

我安装了宝石回形针并进行了设置。我将这段代码放入我的一个控制器中,

@pictures = Picture.near([latitude, longitude], 6.8) #im also using geocoder
@picturethumbs = @pictures
@picturethumbs.each do |thumb|
      thumb.photo = thumb.photo(:thumb)
 end
when i do this in my view
<% @picturethumbs.each do |picture| %>

    <p> <%= link_to image_tag(picture.photo), picture_path(picture) %>

</p><% end %>

我得到了常规大小的图像。 如果我不在控制器中调整大小,但在视图中执行 picture.photo(:thumb) 操作,我会得到正确的拇指。您能帮助我独立于在视图中修改图像来调整图像大小吗?也许是另一个与图片相对应但自动包含拇指的模型(不在视图中调整大小)

I installed the gem paperclip and set it up. I put this piece of code in one of my controllers

@pictures = Picture.near([latitude, longitude], 6.8) #im also using geocoder
@picturethumbs = @pictures
@picturethumbs.each do |thumb|
      thumb.photo = thumb.photo(:thumb)
 end
when i do this in my view
<% @picturethumbs.each do |picture| %>

    <p> <%= link_to image_tag(picture.photo), picture_path(picture) %>

</p><% end %>

i get regular sized images.
If i dont resize in my controller, but i do picture.photo(:thumb) in the view i get the right thumbs. Could you help me resize the image independently of modifying it in the view. Maybe another model which corresponds to pictures but contains automatically thumbs (not resizing in view)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反目相谮 2024-12-15 13:17:49

您能否发布有关如何设置您的模型(使用回形针)的更多详细信息?

您将在您的模型中需要它:

class User < ActiveRecord::Base
  # ...
  has_attached_file :picture, :styles => { :small => "150x150>" }   

end

然后在您的视图中:

<%= image_tag @user.picture.url(:small) %>  

检查此 RailsCast:

Can you please post more details on how your Model is set up, which uses paperclip?

You will need this in your model :

class User < ActiveRecord::Base
  # ...
  has_attached_file :picture, :styles => { :small => "150x150>" }   

end

and then in your view:

<%= image_tag @user.picture.url(:small) %>  

Check this RailsCast:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文