2

我得到的错误

NoMethodError (undefined method `reject' for #<ActionDispatch::Http::UploadedFile:0x007fab6ea5c370>):
  app/controllers/photos_controller.rb:3:in `create'

表格(在 HAML 中)

  %form{:id => 'photo-upload-form', :method => 'post', :action => '/photos', :enctype => 'multipart/form-data'}
    %input{:type => 'file', :id => 'photo', :name => 'photo'}
    %input.btn{:type => 'submit', :value => 'Upload Photo'}

photos_controller.rb 控制器

class PhotosController < ApplicationController
  def create # POST /photos
    photo = Photo.create(params[:photo])
    render :nothing => true
  end
end

photo.rb 模型

class Photo
  include Mongoid::Document
  include Mongoid::Paperclip

  has_mongoid_attached_file :photo,
                            :storage => :s3,
                            :bucket => '<My_Bucket>',
                            :s3_credentials => {
                                :access_key_id => '<My_Access_Key>',
                                :secret_access_key => '<My_Secret_Access_Key>'
                            },
                            :styles => {
                                :thumb  => "100x100",
                                :medium => "200x200",
                                :large => "600x400"
                            }
end

Gemfile(已运行捆绑安装)

gem 'mongoid-paperclip', :require => "mongoid_paperclip"
gem 'aws-sdk'

版本

Ruby 1.9.3
Rails 3.2.3
Mongoid 2.4.8
Mongoid-Paperclip 0.0.7
Paperclip 3.1.2
aws-sdk 1.5.7

代码相当简单,我遵循了文档。不知道我应该怎么做。

4

1 回答 1

1

所以,问题是

    photo = Photo.create(params[:photo])

本来应该

    photo = Photo.create(params)

现在,我希望你能原谅我,我去踢自己。:)

于 2012-07-14T05:25:16.027 回答