Guest User

Untitled

a guest
Jan 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #image_uploader.rb
  2. class ImageUploader < CarrierWave::Uploader::Base
  3. include Cloudinary::CarrierWave
  4. ...
  5. def public_id
  6. return model.title.parameterize+SecureRandom.uuid
  7. end
  8. end
  9.  
  10. # models/author.rb
  11. class Author < ActiveRecord::Base
  12. mount_uploader :image, ImageUploader
  13. end
  14. # views/admin/authors/_form.html.rb
  15. <div class="field">
  16. <%= f.label :image %><br>
  17. <%= f.hidden_field :image_cache %>
  18. <%= f.file_field :image %>
  19. <%= cl_image_tag(@article.image_url, :width => 50, :height => 50, :crop => :fill) if @article.image? %>
  20. </div>
  21.  
  22.  
  23. #controllers/admin/authors_controller.rb
  24.  
  25. module Admin
  26. class AuthorsController < ApplicationController
  27.  
  28. def update
  29. if @author.update(author_params)
  30. redirect_to admin_authors_path, notice: 'author was successfully updated.'
  31. else
  32. render :edit
  33. end
  34. end
  35.  
  36. private
  37.  
  38. def author_params
  39. params.require(:author).permit(:name, :image, :deleted, :email, :twitter, :facebook, :bio_az, :bio_en)
  40. end
  41. end
  42. end
Add Comment
Please, Sign In to add comment