whyvez
whyvez

Reputation: 323

Rails 3, Uploadify and Carierwave

I am trying to implement an uploader using Carrierwave on the server and Uploadify on the client. From the client it seems like its all working and on the server the record gets saved in the db but the physical uploaded file is never saved to the file system. Please keep in mind that I am a newcomer to Rails.

Here is my uploader:

class ShapefileUploader < CarrierWave::Uploader::Base

  storage :file

  # simple path for debugging
  def store_dir
    "uploads" 
  end

end

My model:

class DataRecord < ActiveRecord::Base

  # not too sure if this belongs here at all, documentation is not too specific.
  require 'carrierwave/orm/activerecord'

  mount_uploader :shapefile, ShapefileUploader

end

One thing i don't fully understand from the Carrierwave documentation is the part about making sure you are loading CarrierWave after loading your ORM. I don't fully understand what its means.

My controller:

class DataRecordsController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:update, :create]

  def index
   @folder = Folder.find(params[:folder_id])
   @data_types = DataType.all
  end 

  def create
    data_record = DataRecord.new({:shapefile => params[:Filedata], :folder_id =>    params[:folder_id], :user_file_name => params[:Filename], :data_type_id => 6})
    data_record.save!
  end

  def update

  end

end

In the create action asides from the actual file upload the rest of the data I am setting manually for debugging.

This all seems to work without any errors.

Here is the posted data:

Parameters: {"Filename"=>"id_rsa.pub", "Filedata"=>#<ActionDispatch::Http::UploadedFile:0x007fc67836eb88 @original_filename="id_rsa.pub",   @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"Filedata\"; filename=\"id_rsa.pub\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:/tmp/RackMultipart20120531-4919-147n4qu>>, "Upload"=>"Submit Query",  "folder_id"=>"74"}

SQL INSERT:

INSERT INTO "data_records" ("data_type_id", "folder_id", "shapefile", "status", "uploaded_date_time", "user_file_name", "validated", "validation_results", "validation_to_send") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id"  [["data_type_id", 6], ["folder_id", 74], ["shapefile", "id_rsa.pub"], ["status", 0], ["uploaded_date_time", nil], ["user_file_name", "id_rsa.pub"], ["validated", 0], ["validation_results", nil], ["validation_to_send", nil]]

I know there are some issues in regards to flash dropping cookies but I think I have worked around this for debugging purposes by skipping checking the authenticity token on the create action. I have changed the security permissions on the upload folder to world read/write. Another confusion I encountered on the github Carrierwave documentation is the following code:

u.avatar = File.open('somewhere')

Is this required? If so why and what does it do?

Help would be greatly appreciated. Thank You!

Upvotes: 1

Views: 684

Answers (1)

whyvez
whyvez

Reputation: 323

Figured it out! Uploaded files will be placed into /public/uploads. Likely a rookie mistake but would be nice if this was explained better in the documentation.

Upvotes: 1

Related Questions