I'm building a Rails application in which MongoDB as database and i have created a form to upload files to the rails public directory and save details in the database.
For uploading, I use gem called carrierwave. when i tried to save from my form i have managed to save the uploaded file details in the database but I'm not able to upload the file into the public directory. i will write down code which i have tried if any changes needed please assist me on it.
i have configured uploader as follows:
class DocumentUploader < CarrierWave::Uploader::Base
storage :grid_fs
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def cache_dir
"#{Rails.root}/tmp/uploads"
end
end
in model:
class Branch
include Mongoid::Document
---
mount_uploader :icon, DocumentUploader
end
in controller:
class BranchesController < ApplicationController
def new
@branch = Branch.new
end
def create
@branch = Branch.new(branch_param)
@branch.save
end
private
def branch_param
params.require(:branch).permit(:name, :icon)
end
end
and the form view is as follows:
<%= form_for @branch do |f| %>
----
<%= f.file_field :icon %>
<%= f.submit 'save' %>
<% end %>
I'm building a Rails application in which MongoDB as database and i have created a form to upload files to the rails public directory and save details in the database.
For uploading, I use gem called carrierwave. when i tried to save from my form i have managed to save the uploaded file details in the database but I'm not able to upload the file into the public directory. i will write down code which i have tried if any changes needed please assist me on it.
i have configured uploader as follows:
in model:
in controller:
and the form view is as follows:
in my Gem list i have added few gems like
Thanks in advance