我得到的错误
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(已运行bundle install)
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
代码非常简单,我遵循了文档。不知道我该怎么做。
答案 0 :(得分:1)
所以,问题是
photo = Photo.create(params[:photo])
应该是
photo = Photo.create(params)
现在,我希望你能在我自己踢的时候原谅我。 :)