ruby on rails 3 - nginx upload module -
i having trouble getting nginx upload module working rails application.
my route
match '/images/fast_upload' => 'images#create', :via => :post
image model
attr_accessor :tmp_upload_dir after_create :clean_tmp_upload_dir # handle new param def fast_asset=(file) if file && file.respond_to?('[]') self.tmp_upload_dir = "#{file['filepath']}_1" tmp_file_path = "#{self.tmp_upload_dir}/#{file['original_name']}" fileutils.mkdir_p(self.tmp_upload_dir) fileutils.mv(file['filepath'], tmp_file_path) self.asset = file.new(tmp_file_path) end end private # clean tmp directory used in handling new param def clean_tmp_upload_dir fileutils.rm_r(tmp_upload_dir) if self.tmp_upload_dir && file.directory? (self.tmp_upload_dir) end
nginx.conf
upload_pass @fast_upload_endpoint; upload_store /pathto/shared/uploads_tmp 1; upload_store_access user:rw group:rw all:r; upload_set_form_field upload[fast_asset][original_name] "$upload_file_name"; upload_set_form_field upload[fast_asset][content_type] "$upload_content_type"; upload_set_form_field upload[fast_asset][filepath] "$upload_tmp_path"; upload_pass_form_field "^image_id$|^authenticity_token$|^format$"; upload_cleanup 400 404 499 500-505; } location @fast_upload_endpoint { passenger_enabled on; rails_env production; } location / { rails_env production; passenger_enabled on; }
in controller create method
def create @image = current_user.images.build(params[:image]) if @image.save
basically i'm not sure how create method use nginx upload. tried use @image = @resource.current_user.images.build(params[:image]) giving me undefined method error.
what should check parameters nginx passes when creating upload. have same logic do. create action i've got follows. bear me because i'm not able test parameters nginx passes now. think it's not "image" "upload"
@photo = @artist.photos.build(params[:upload])
is create method.
Comments
Post a Comment