Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #image_uploader.rb
- class ImageUploader < CarrierWave::Uploader::Base
- include Cloudinary::CarrierWave
- ...
- def public_id
- return model.title.parameterize+SecureRandom.uuid
- end
- end
- # models/author.rb
- class Author < ActiveRecord::Base
- mount_uploader :image, ImageUploader
- end
- # views/admin/authors/_form.html.rb
- <div class="field">
- <%= f.label :image %><br>
- <%= f.hidden_field :image_cache %>
- <%= f.file_field :image %>
- <%= cl_image_tag(@article.image_url, :width => 50, :height => 50, :crop => :fill) if @article.image? %>
- </div>
- #controllers/admin/authors_controller.rb
- module Admin
- class AuthorsController < ApplicationController
- def update
- if @author.update(author_params)
- redirect_to admin_authors_path, notice: 'author was successfully updated.'
- else
- render :edit
- end
- end
- private
- def author_params
- params.require(:author).permit(:name, :image, :deleted, :email, :twitter, :facebook, :bio_az, :bio_en)
- end
- end
- end
Add Comment
Please, Sign In to add comment