私は最初の Rails アプリに Paperclip を実装しようとしていますが、たまたま Rails 3 と mongodb を mongomapper で使用しています。
私はこのガイドに従って、すべてがうまく機能するようにしました
ブログ投稿が示唆するように、ペーパークリップを config/initializers ディレクトリに配置し、gem をインストールし、gem ファイル (Rails 3 の右) にあり、bundler を実行しました。
私のユーザークラスでは、追加しました
「ペーパークリップ」が必要
アプリをロードすると、次のエラーが表示されます。
User:Class の未定義のメソッド 'has_attached_file'
クリップファイルはこんな感じ
モジュール ペーパークリップ モジュール ClassMethods def has_attached_file 名、オプション = {} InstanceMethods を含める write_inheritable_attribute(:attachment_definitions, {}) if attachment_definitions.nil? attachment_definitions[name] = {:validations => []}.merge(オプション) after_save :save_attached_files before_destroy :destroy_attached_files define_callbacks :before_post_process, :after_post_process define_callbacks :"before_#{name}_post_process", :"after_#{name}_post_process" define_method name do |*args| a = attachment_for(名前) (args.length > 0) ? a.to_s(args.first) : a 終わり define_method "#{name}=" do |ファイル| attachment_for(name).assign(ファイル) 終わり define_method "#{name}?" 行う attachment_for(name).file? 終わり validates_each name, :logic => lambda { attachment = attachment_for(name) attachment.send(:flush_errors) attachment.valid? } 終わり 終わり モジュール補間 # 文字列 ID の処理 (mongo) def id_partition アタッチメント、スタイル if (id = attachment.instance.id).is_a?(整数) ("%09d" % id).scan(/\d{3}/).join("/") そうしないと id.scan(/.{3}/).first(3).join("/") 終わり 終わり 終わり 終わり
私が間違っているかもしれないことについて何か提案はありますか? 手順は正しいですか?