In my project I currently have different models (Project, Message, etc) that:
has_many :assets, :as => :attachable, :dependent => :destroy
Each Asset is basically a model with a CarrierWave file. Normally I would just use accepted_nested_attributes on the parent model (Project, Message, etc) and have the file upload fields listed in a fields_for block.
My problem is that since I’m using jQuery-File-Uploader with AJAX the parent model’s form will call the parent model’s Create method when ever a file is uploaded. The rest of the parent model fields might not be filled out yet. I’m thinking maybe I could have the file uploader call the create method in the Assets controller, but then I would some how have to send the parent model’s class so the polymorphic association is stored correctly.
Any ideas of how I might get this working cleanly? Thanks for looking.
OK.
Step 1
add
gem 'carrier wave'to you GemfileStep 2
save the code to
/lib/flash_session_cookie_middleware.rbStep3
edit
session_store.rbadd the code to the end of fileStep4
Download jquery.uploadify.js from Uploadify and unzip it.
Step5
jquery.uploadify.v2.1.4.min.js&swfobject.jsto/app/assets/javascriptsif you use Rails3.1 or later, to/public/javascriptsif you use Rails 3.0 or before version.uploadify.swfandcancel.pngto/app/assets/images/or/public/imagesuploadify.cssto/app/assets/stylesheets/or/public/stylesheetsStep6
Edit your application.js, insert below code to it
Step7
In you upload page, add this
Step8
add this code to you upload page
Step9
Write your controller like this