【问题标题】:Image cannot be retrieved from the cloudinary server无法从云服务器检索图像
【发布时间】:2012-11-25 22:32:54
【问题描述】:

我使用Cloudinary Gem 来管理图像。我是 ruby​​ on rails 的新手,所以无法找到我错的地方。图像上传到云服务器已完成,但我无法从服务器检索图像。我将我的视图、控制器和上传器类放在这里。如前所述,我已经安装了载波并将其粘贴在 gem 文件中的 cloudinary gem 之前。

控制器console.rb

class ConsoleController < ApplicationController
layout 'console'
def c_view
 @img = Image.new
end
def create
@img = Image.new(params[:img])
  if @img.save
   redirect_to(:action => 'c_view')
  else
   render('c_view')
  end    
 end
end

ImageUploader 类

class ImageUploader < CarrierWave::Uploader::Base
 include Cloudinary::CarrierWave
def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :standard do
  process :eager => true
  process :resize_to_fill => [1200, 800, :north]          
  end

version :thumb do
 eager 
 resize_to_fit(200, 200)
end

def public_id
 return model.photo_file_name
end
end

观看次数

上传

<%= form_for :img, :url => {:action => "create"} do |f| %>

<%= f.label :gallery, "Gallery"%>
    <%= f.select :gallery, ["Art", "Bike", "Landscape", "Other", "Portrait"] %> 

    <%= f.label :photo_file_name, "Title" %>
<%= f.text_field :photo_file_name %>

<%= f.label :camera_model, "Camera" %>
<%= f.text_field :camera_model %>

<%= f.label :lens_used, "Lens" %>
<%= f.text_field :lens_used %>

<%= f.label :shutter_speed, "Shutter Speed" %>
<%= f.text_field :shutter_speed %>

<%= f.label :aperture, "Aperture" %>
<%= f.text_field :aperture %>

<%= f.label :iso, "ISO" %>
<%= f.text_field :iso %>

<%= f.label :description, "Description" %>
<%= f.text_area :description, :rows => 2 %>

<%= f.file_field :image %>      

<%= f.submit "Submit", class: "btn btn-success"%>

<% end %>

用于展示

<%= image_tag (@img.image_url :thumb, :width => 200, :height => 200) %>

模型图片

class Image < ActiveRecord::Base
belongs_to :user
 attr_accessible :id, :user_id, :name, :camera_model, :lens_used, :shutter_speed,   :aperture, :iso, :gallery, :description, :photo_file_name, :photo_file_size, :photo_updated_at, :image, :image_url 
mount_uploader :image, ImageUploader
end

它没有显示任何错误。上传部分正在工作,但图像检索不起作用。 请帮忙。

【问题讨论】:

    标签: ruby-on-rails cloudinary


    【解决方案1】:

    天哪……!!!!

    我是最愚蠢的..对不起伙计们..Rofl...!!

    我没有把节目放在控制器里。所以只需要在控制器中添加这些行,视图如下:

    在控制器中

    @images = Image.all
    

    在视图中

    <% @images.each do |img| %>
      <%= image_tag(img.image.url (:thumb))
    <% end %>
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      • 1970-01-01
      相关资源
      最近更新 更多