ruby on rails - Changing cloudinary file default url per uploader -


i have rails 4 app ruby 2.2.0.

i building app need store quite bit of images. app exists , managing images on local server, want change that.

the app deployed on heroku , want use cloudinary service upload(using carrierwave) new images store existing ones.

the issue comes fact can't seem able adopt current folder structure platform using. start uploaded files via media manager in cloudinary dashboard. created 2 folders header , logo. in case refer header folder example.

class banneruploader < carrierwave::uploader::base   include cloudinary::carrierwave    def store_dir     "uploads/header/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"   end end 

the model:

class companyimage < activerecord::base    mount_uploader :file_name, banneruploader    belongs_to :company end 

and last not least, here view:

<%   work_advantages = company.presentation.work_advantages   banner = company.company_images.where(header: true).first %> <%= link_to company %>   <div class="card company-presentation-card card-hover">     <div class="card-container">       <div class="row">         <div class="col-md-12">           <div class="cover-image">           </div>           <h3><%= company.name %></h3>           <% company.company_sectors.each |s| %>             <span class="h4-alt1 company-sector"><%= s.sector.name %></span>           <% end %>           <p><%= truncate(company.presentation.work_advantages, :length => 250) %> <span class="text-muted">(lees meer)</span></p>         </div>       </div>     </div>   </div> <% end %>  <script>   //set dynamic background image cover-image <div>   $(document).ready(function(){     $('.company-presentation-card').find('.cover-image').css('background-image', 'url("<%= banner.file_name %>")')   }); </script> 

currently, url being delivered in following: http://res.cloudinary.com/hxwmb9swy/image/upload/5a444a7c191e8c98999f6d0c2d3afaf9_arendsen_machinefabriek.jpg need have header(the folder created in cloudinary) folder in there url should this: http://res.cloudinary.com/hxwmb9swy/image/upload/header/5a444a7c191e8c98999f6d0c2d3afaf9_arendsen_machinefabriek.jpg

of course in case of logo, same instead of header should logo. apply other models. question how can manage in way, can specify folder per uploader? ideas welcome.

the header or logo should included in image's public id. if server-side upload, can override public_id method in uploader include folder. example, following sets public id header folder original image's filename (without extension, should):

def public_id     basename = file.basename(original_filename, file.extname(original_filename))     "header/#{basename}" end 

if client-side upload, cloudinary's cl_image_upload example, can like:

<%= f.cl_image_upload(:image, :folder => "header") %> 

for 2nd case, there's no need change in uploader.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -