Created
October 29, 2014 17:04
-
-
Save darkslategrey/a583ec36bbe1a01593d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
has_and_belongs_to_many :elearning_requests | |
end | |
class ElearningRequest | |
include Mongoid::Document | |
include Mongoid::Timestamps::Short | |
include Mongoid::Enum | |
# ---------------------------------------------------------------------------- | |
# Fields --------------------------------------------------------------------- | |
# ---------------------------------------------------------------------------- | |
field :title, type: String, localize: true | |
field :description, type: String, localize: true | |
enum :status, [:pending, :approved, :declined], default: :pending | |
# ---------------------------------------------------------------------------- | |
# Relations ------------------------------------------------------------------ | |
# ---------------------------------------------------------------------------- | |
belongs_to :user | |
has_and_belongs_to_many :documents | |
end | |
class Document | |
include Mongoid::Document | |
include Mongoid::Timestamps::Short | |
mount_uploader :file, DocumentUploader | |
belongs_to :elearning_request | |
end | |
class DocumentUploader < CarrierWave::Uploader::Base | |
def store_dir | |
"/elearning_request/documents/#{model.id}" | |
end | |
def extension_white_list | |
%w(pdf) | |
end | |
end | |
# dans la forme | |
# = form_for [:account, elearning_request] do |f| | |
# ... | |
# = f.fields_for :documents do |fo| | |
# = fo.file_field :file, name: 'elearning_request[documents][]' | |
# Et enfin les logs du serveur: | |
17:37:02 web.1 | Processing by Account::ElearningRequestsController#create as HTML | |
17:37:02 web.1 | Parameters: {"utf8"=>"✓", "authenticity_token"=>"uNIaFg3x+UJ4oYLPQrMGb276WpQa8InST7swv8O1tk4=", "elearning_request"=>{"title_translations"=>{"fr"=>"dfsfds", "en"=>"fdsfds"}, "description_translations"=>{"fr"=>"fdsfds", "en"=>"fdsfds"}, "documents"=>[#<ActionDispatch::Http::UploadedFile:0x007f7f78f7ca20 @tempfile=#<Tempfile:/tmp/RackMultipart20141029-29535-zfijfh>, @original_filename="CraftingRails4App.pdf", @content_type="application/pdf", @headers="Content-Disposition: form-data; name=\"elearning_request[documents][]\"; filename=\"CraftingRails4App.pdf\"\r\nContent-Type: application/pdf\r\n">]}, "locale"=>"fr"} | |
17:37:02 web.1 | MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} runtime: 0.4398ms | |
17:37:02 web.1 | MOPED: 127.0.0.1:27017 QUERY database=travel_development collection=users selector={"$query"=>{"_id"=>BSON::ObjectId('5450e84f63626d02a1040000')}, "$orderby"=>{:_id=>1}} flags=[] limit=-1 skip=0 batch_size=nil fields=nil runtime: 0.4677ms | |
17:37:02 web.1 | Document ... #<ActionDispatch::Http::UploadedFile:0x007f7f78f7ca20> | |
17:37:02 web.1 | MOPED: 127.0.0.1:27017 UPDATE database=travel_development collection=documents selector={"$and"=>[{"_id"=>{"$in"=>[]}}]} update={"$pull"=>{"elearning_request_ids"=>BSON::ObjectId('545117ae63626d735f140000')}} flags=[:multi] | |
17:37:02 web.1 | COMMAND database=travel_development command={:getlasterror=>1, :w=>1} runtime: 0.7122ms | |
17:37:02 web.1 | Completed 500 Internal Server Error in 17ms | |
17:37:02 web.1 | | |
17:37:02 web.1 | NoMethodError - undefined method `id' for #<ActionDispatch::Http::UploadedFile:0x007f7f78f7ca20>: | |
17:37:02 web.1 | mongoid (4.0.0) lib/mongoid/relations/targets/enumerable.rb:62:in `<<' | |
17:37:02 web.1 | mongoid (4.0.0) lib/mongoid/relations/referenced/many_to_many.rb:209:in `append' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
C'est réglé ça ?