Ruby on rails e> //=require cloudinary我所需要做的就是在cl\u image\u upload助手前面添加f.。因此,f.cl\u image\u upload:asset现在正在为我工作。 .image-field-group .field
Ruby on rails e> //=require cloudinary我所需要做的就是在cl\u image\u upload助手前面添加f.。因此,f.cl\u image\u upload:asset现在正在为我工作。 .image-field-group .field,ruby-on-rails,carrierwave,cloudinary,Ruby On Rails,Carrierwave,Cloudinary,e> //=require cloudinary我所需要做的就是在cl\u image\u upload助手前面添加f.。因此,f.cl\u image\u upload:asset现在正在为我工作。 .image-field-group .field = f.label :asset, "Image" = cl_image_upload :asset / = f.file_field :asset / = f.hidden_field :asset_cach
e> //=require cloudinary我所需要做的就是在
cl\u image\u upload
助手前面添加f.
。因此,f.cl\u image\u upload:asset
现在正在为我工作。
.image-field-group
.field
= f.label :asset, "Image"
= cl_image_upload :asset
/ = f.file_field :asset
/ = f.hidden_field :asset_cache
- if f.object && f.object.asset && f.object.asset.filename
.image-box
= cl_image_tag(f.object.asset.filename.to_s, :transformation => 'hint', alt: f.object.asset.filename.to_s)
.remove-fields
= link_to_remove_fields f
class Image < ActiveRecord::Base
default_scope order('images.id ASC')
attr_accessible :asset,
:asset_cache
belongs_to :imageable, polymorphic: true
mount_uploader :asset, ImageUploader
end
class ImageUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
def extension_white_list
%w(jpg jpeg gif png)
end
end
class ImagesController < ApplicationController
before_filter :load_imageable
def index
@images = @imageable.images
end
def new
@image = @imageable.images.new
end
def create
@image = @imageable.images.new(params[:image])
if @image.save
redirect_to @imageable, notice: "Image created."
else
render :new
end
end
private
def load_imageable
resource, id = request.path.split('/')[1, 2]
@imageable = resource.singularize.classify.constantize.find(id)
end
end
= form_for(:entity) do |f|
= f.cl_image_upload(:asset)
- if f.object && f.object.asset.present?
.image-box
= cl_image_tag(f.object.asset, :transformation => 'hint', alt: f.object.asset.filename.to_s)