我正在为web应用程序(在unix/linux上运行)进行文件上传.我想知道如果我打算为每个文件上传创建一个新目录,是否会引起关注?这是Ruby on Rails插件"paperclip"的开箱即用方法.如果在Linux/unix环境中部署,我会讨论权衡取舍,或者是否只是一个问题.
选项似乎是:
问题 - 我应该关注正在创建的目录数量吗?如果服务很受欢迎,这是否是O/S的问题?对于允许用户使用自己的单独帐户上传文件的网站的任何建议,在存储文件时哪种结构可能是好的?(我想我已经打消了在mysql中存储文件的概念.)
谢谢
有谁知道我如何配置使用回形针进行数据存储的Rails模型,以使用基于创建日期的目录,例如在fleximage中?
目前,我正在使用:
has_attached_file :bookblock, :path => "#{CONF['storage_path']}bookblock/:id_partition/:style.:content_type_ehas_attached_filextension"
Run Code Online (Sandbox Code Playgroud)
但是我需要的是这样的东西
has_attached_file :bookblock, :path => "#    {CONF['storage_path']}bookblock/:created_at_year/:created_at_month/:created_at_day/:c:id_partition/:style.:content_type_ehas_attached_filextension"
Run Code Online (Sandbox Code Playgroud)
在目录路径中一个简单的:created_at也会有帮助
{CONF['storage_path']}/:created_at/bookblock/:id_partition/:style.:content_type_ehas_attached_filextension"
Run Code Online (Sandbox Code Playgroud)
提前感谢,
亚历克斯
我试图找出如何让用户从他们的计算机上传照片或从Facebook获取照片.
我已经有一个表单用于上传图像并使用Paperclip插件保存它.这很好.
我已经设置了Facebook身份验证,并使用Koala gem访问Facebook图形API.
我已经写过这个方法:
def fetch_fb_picture
 unless current_user.authentications.blank?  
  @graph = Koala::Facebook::GraphAPI.new(current_user.authentications.find_by_provider("facebook").token)
  @picture = @graph.get_picture("#{current_user.authentications.find_by_provider('facebook').username}")
  current_user.profile.photo = @picture
 end
end
Run Code Online (Sandbox Code Playgroud)
我相信Koala gem返回图像的url.但是,由于我正在使用paperclip gem,我的配置文件接受以下属性:
t.string   "photo_file_name"
t.string   "photo_content_type"
t.integer  "photo_file_size"
Run Code Online (Sandbox Code Playgroud)
因此,如何将Facebook图像正确保存到数据库中?
我正在使用回形针gem将图像上传到s3 amazone。正在上传三份图片-一幅是真实的,两幅具有不同的分辨率,例如10x10,50x50。
现在,我要上传5张图像的副本,例如10x10、20x20 ............这可以通过在模型中指定尺寸来完成。
但是s3上的现有图像呢?如何在s3上创建现有图像的副本?
我有一个带有一个回形针附件的模型:图像
模型:
class HomeScreen < ActiveRecord::Base
  before_create { !HomeScreen.has_record? }
  validates :image, :attachment_presence => true
  attr_accessible :image
  has_attached_file :image
  def self.has_record?
    if HomeScreen.last
      true
    else
      false
    end
  end
end
Run Code Online (Sandbox Code Playgroud)
我的conttroller的show方法应该返回带有相对路径的图像,但是json应该返回带域的绝对url,我该怎么办呢?
控制器:
class HomeScreenController < ApplicationController
  # GET /home_screen
  def show    
    @home_screen = HomeScreen.last
    respond_to do |format|
      format.html
      format.json { render json: @home_screen }
    end
  end
Run Code Online (Sandbox Code Playgroud) 我正在寻找为rails app加载用户头像的最佳方式.
有一些重要的案例:
我找到了 https://github.com/ging/avatars_for_rails,但在任何替代品或好样品中都很有趣.
我有四个型号,我们称之为汽车和房屋.用户可以拥有多辆汽车和多个房屋.汽车和房屋属于用户.我希望用户能够上传他们汽车的多张照片,以及他们房屋的多张照片,从我读到的这意味着创建一个名为"照片"的新模型.两个不同的模型是否可以同时拥有多张照片,而照片属于多个模型?我正在使用Ruby 2.0.0和Rails 4.
Sketch/PseudoRuby
User
  has_many :cars
  has_many :houses
Car
  belongs_to :user
  has_many :photos
House
  belongs_to :user
  has_many :photos
Photo
  belongs_to :car, :house
Run Code Online (Sandbox Code Playgroud)
这段关系好吗?我不确定是否必须为Car and House的照片制作单独的模型.
我正在尝试使用Rails 4中的Paperclip和Formtastic为图像创建一个简单的上传表单.我在加载表单视图时收到此错误消息:
wrong number of arguments (1 for 0) 
Run Code Online (Sandbox Code Playgroud)
这是我的_form.html.erb:
<%= semantic_form_for @image, :html => { :multipart => true } do |f| %>
    <%= f.input :attachment, :as => :file %>
    <%= f.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
当我使用常规rails file_field助手时,它工作正常,如下所示:
<%= f.file_field :attachment %>
Run Code Online (Sandbox Code Playgroud)
这是我的模特:
class Image < ActiveRecord::Base
  has_attached_file :attachment, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
  validates_attachment_content_type :attachment, :content_type => /\Aimage\/.*\Z/
end
Run Code Online (Sandbox Code Playgroud)
这是我的gemfile的一部分:
ruby "2.1.0"
gem 'rails', '4.0.2'
gem "formtastic", github: "justinfrench/formtastic"
gem "paperclip", …Run Code Online (Sandbox Code Playgroud) 当我使用formtastic DSL for ActiveAdmin编辑表单时,我得到以下输出:
#<#<Class:0x00000006bd1f68>:0x00000006bd1018> <li class ="file input optional"id ="post_image_input"> <label class ="label"for ="post_image"> Image </ label> <input id ="post_image "name ="post [image]"type ="file"/>
为什么这会从obj.inspect的结果以及如何删除这部分开始呢?
导致此错误的代码在这里:
form :html => { :multipart => true } do |f|
    f.inputs do
        #...
        f.input :image, required: false, hint: f.template.image_tag(f.object.image.url(:medium)).html_safe
        #...
    end
    f.actions
end
Run Code Online (Sandbox Code Playgroud) 对不起,但我无法找到适合我情况的解决方案
我有下一个代码:
class Document < ActiveRecord::Base
    has_attached_file :item,
                 content_type: { content_type: ["image/jpeg",    "image/gif", "document/pdf"] } 
end
Run Code Online (Sandbox Code Playgroud)
的Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more …Run Code Online (Sandbox Code Playgroud) paperclip ×10
formtastic ×2
ruby ×2
activeadmin ×1
amazon-s3 ×1
attachment ×1
avatar ×1
carrierwave ×1
date ×1
facebook ×1
file-upload ×1
jcrop ×1
unix ×1