Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 回形针-每个样式的默认样式?可能的_Ruby On Rails_Ruby On Rails 3_Paperclip - Fatal编程技术网

Ruby on rails 回形针-每个样式的默认样式?可能的

Ruby on rails 回形针-每个样式的默认样式?可能的,ruby-on-rails,ruby-on-rails-3,paperclip,Ruby On Rails,Ruby On Rails 3,Paperclip,我用的是回形针,有几种款式: :styles => {:large => "300x300>", :medium => "150x150>", :small => "50x50>", :thumb => "30x30>" } 问题是默认样式,仅适用于其中一种大小。。。 :default_style=>:thumb, :default_url=>此处的url 如何为每种样式类型设置默认样式?因此,如果我打电话: 大样式有默认的url吗 谢谢

我用的是回形针,有几种款式:

:styles => {:large => "300x300>", :medium => "150x150>", :small => "50x50>", :thumb => "30x30>" }
问题是默认样式,仅适用于其中一种大小。。。 :default_style=>:thumb, :default_url=>此处的url

如何为每种样式类型设置默认样式?因此,如果我打电话:

大样式有默认的url吗


谢谢

我建议使用

has_attached_file :xyz, :url  => "/assets/:id", :path => ":rails_root/assets/photos/:attachable_type/:attachable_id/:id/:basename_:style.:extension",
                  :styles => { :large => "300x300>", :medium => "150x150>", :small => "50x50>", :thumb => "30x30>"}
为了得到合适的风格

/资产/:id?样式=:样式

像localhost:3000/assets/10?style=medium

注意:attachable_type、attachable_id来自多态关系

希望对你有帮助

rgds


Kannan R

这相当容易。只需在/config/initializer中创建paperclip.rb,并在其中放置类似的内容:

module Paperclip
  class Attachment
    def self.default_options
      @default_options ||= {
        :url               => "/system/:class/:id/:style_:filename",
        :path              => ":rails_root/public:url",
        :styles            => {},
        :processors        => [:thumbnail],
        :convert_options   => {},
        :default_url       => "/images/missing/:class_:attachment_:style.jpg",
        :default_style     => :original,
        :storage           => :filesystem,
        :whiny             => Paperclip.options[:whiny] || Paperclip.options[:whiny_thumbnails]
      }
    end
  end
end

这将覆盖默认值。因此,您可以继续将:default_style更改为您想要的任何样式。

请在发布答案时格式化您的代码(使用4个空格缩进),谢谢,但我不知道如何设置每个样式的默认图像?应该有默认的_profile_pic_large.png、默认的_profile_pic_medium.png、默认的_profile_pic_small.png、默认的_profile_pic_thumb.png。我不确定我是否遵循了上述解决方案?我没有挑战获得一个特定的风格,只是让它足够聪明,去默认每个风格。想法?默认应该是一种风格,不是吗?如果你正在寻找一些东西,比如如果用户没有上传图像,那么在一些地方你想使用默认的大图像,而在其他一些地方你想使用默认的小图像,默认的拇指图像。。。根据groffy:default\u url=>“/images/missing/default\u profilepic\uu:style.jpg”应该可以解决您的问题