【问题标题】:ruby on rails gallery ArgumentError Unknown key(s): attributes, discard_if attachment_fu and paperclipruby on rails gallery ArgumentError 未知键:属性、discard_if attachment_fu 和回形针
【发布时间】:2011-04-04 10:03:22
【问题描述】:

您好,我正在尝试为自己建立一个小画廊,并尝试使用此链接多次上传专辑:http://www.mfischer.com/wordpress/2009/02/02/multiple-image-upload-and-crop-with-rails/

到目前为止,当我访问 localhost:3000/albums/new 时遇到以下错误:

ArgumentError in AlbumsController#index
Unknown key(s): attributes, discard_if

由于我不确定 attach_fu-Plugin 和回形针-gem(我使用的)是否正确使用,也许这也是一个问题?

我的其他版本:

Ruby version    1.9.2 (x86_64-linux)
RubyGems version    1.7.1
Rack version    1.2
Rails version   3.0.4
Active Record version   3.0.4
Action Pack version 3.0.4
Active Resource version 3.0.4
Action Mailer version   3.0.4
Active Support version  3.0.4

无法说出确切的 attachment_fu 版本... :/ 回形针版本是这样的:

paperclip (2.3.8)

My album model is this:
# == Schema Information
# Schema version: 20110404082122
#
# Table name: albums
#
#  id         :integer         not null, primary key
#  name       :string(255)
#  location   :string(255)
#  date       :date
#  created_at :datetime
#  updated_at :datetime
#

class Album < ActiveRecord::Base
  has_many  :images,
        :attributes => true,
        :discard_if => proc { |upload| upload.photo_file_size.nil? }
end

而我的图像模型是这样的:

# == Schema Information
# Schema version: 20110404082122
#
# Table name: images
#
#  id          :integer         not null, primary key
#  name        :string(255)
#  date        :date
#  landscape   :boolean
#  flash       :boolean
#  cameramaker :string(255)
#  cameramodel :string(255)
#  lens        :string(255)
#  flength     :string(255)
#  aperture    :string(255)
#  exposure    :string(255)
#  iso         :string(255)
#  album_id    :integer
#  filesize    :integer
#  created_at  :datetime
#  updated_at  :datetime
#

require 'RMagick'

class Image < ActiveRecord::Base
  belongs_to :album
  has_attached_file :photo,
            :styles => {
              :thumb => ["150x150", :jpg],
              :pagesize => ["500x400", :jpg],
            },
            :default_style => :pagesize
end

你还需要什么吗? 我不明白问题出在哪里.. 我认为 attachment_fu 插件太旧或者我错过了一些要说的东西来使用它...?

感谢您的宝贵时间!

万夜

【问题讨论】:

    标签: ruby ruby-on-rails-3 paperclip attachment-fu


    【解决方案1】:

    http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many

    has_many 关联没有任何 :attributes:discard_if 选项

    看起来该教程作者使用了attribute_fu 插件。所以你需要安装它

    https://github.com/jamesgolick/attribute_fu

    【讨论】:

    • 所以我应该改用 has_attachment 吗?因为在 [link]mfischer.com/wordpress/2009/02/02/… 他使用 has_many 和这些属性...
    • 我做了,这似乎不太可操作...因为这是输出:[me@pc gallery]$ rails plugin install http://github.com/woahdae/attachment_fu.git -r rails3 Initialized empty Git repository in /home/wayne/DEV/ror/gallery/vendor/plugins/attachment_fu/.git/ remote: Counting objects: 71, done. remote: Compressing objects: 100% (67/67), done. remote: Total 71 (delta 11), reused 25 (delta 0) Unpacking objects: 100% (71/71), done. From http://github.com/woahdae/attachment_fu * branch rails3 -&gt; FETCH_HEAD 并且省略了更多输出,说明如何使用插件。
    • 我没用过这个插件。您是否重新启动了应用?
    • 是的,多次重启 Rails 服务器。也许它不能与 rails 3.0.4 一起正常工作:/
    • 查看插件的文档。我不喜欢使用它们
    猜你喜欢
    • 2015-11-14
    • 2017-01-14
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    相关资源
    最近更新 更多