加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – rails carrierwave_direct无法呈现direct_uplo

发布时间:2020-12-17 03:04:29 所属栏目:百科 来源:网络整理
导读:我尝试在我的rails 3.2应用程序中为某些图像上传设置了carrierwave_direct,但似乎无法使用direct_upload_form_for标记呈现表单. 我收到错误“未定义的方法`direct_fog_url’用于# PostmarkerImage:0x007fdbe07b39f0”加载包含表单的页面时. PostmarkerImage
我尝试在我的rails 3.2应用程序中为某些图像上传设置了carrierwave_direct,但似乎无法使用direct_upload_form_for标记呈现表单.

我收到错误“未定义的方法`direct_fog_url’用于#< PostmarkerImage:0x007fdbe07b39f0>”加载包含表单的页面时.

PostmarkerImage是我安装上传器的模型,如下所示:

class PostmarkerImage < ActiveRecord::Base
  attr_accessible :image,:image_cache

  belongs_to :postmarker

  validates :image,:presence => true

  mount_uploader :image,PostmarkerImageUploader
end

image列是一个字符串,我还确保已运行迁移以创建列.上传者现在看起来像这样:

class PostmarkerImageUploader < CarrierWave::Uploader::Base
  include CarrierWaveDirect::Uploader

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick

  # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
  include Sprockets::Helpers::RailsHelper
  include Sprockets::Helpers::IsolatedHelper

  # Choose what kind of storage to use for this uploader:
  # storage :file
  # storage :fog

  include CarrierWave::MimeTypes
  process :set_content_type

  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url
  #   # For Rails 3.1+ asset pipeline compatibility:
  #   # asset_path("fallback/" + [version_name,"default.png"].compact.join('_'))
  #
  #   "/images/fallback/" + [version_name,"default.png"].compact.join('_')
  # end

  # Process files as they are uploaded:
  # process :scale => [200,300]
  #
  # def scale(width,height)
  #   # do something
  # end

  # Create different versions of your uploaded files:
  # version :thumb do
  #   process :scale => [50,50]
  # end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  def extension_white_list
    %w(jpg jpeg gif png)
  end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here,see uploader/store.rb for details.
  # def filename
  #   "something.jpg" if original_filename
  # end

end

我还确保已经安装了carrierwave_direct,fog,mini_magick和Imagemagick.我可以知道我还错过了什么吗?看起来上传器的安装似乎没有正确完成.

解决方法

管理想出来:)以防万一有人有这个问题:

我正在实现一个单独的模型来保存我的图像,而不是将列添加到现有的表中.因此,direct_upload_form_for需要列(例如Image.new.image)而不是我返回的Object(例如Image.new).我想我被form_for部分抛弃了,它通常需要一个Object!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读