2012-12-07 47 views
0

我使用Cloudinary Gem來管理圖像。我是一個新的紅寶石在軌道上,所以無法找到我錯在哪裏。將圖像上傳到雲端服務器已完成,但我無法從服務器上檢索圖像。我把我的看法,控制器和上傳類放在這裏。我已經安裝了載波,並將其粘貼到前面提到的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 

它沒有顯示任何錯誤。上傳部分正在工作,但圖像的檢索不起作用。 請幫忙。

回答

1

哦,我的上帝...... !!!!

我是所有人中最愚蠢的一個..對不起,.. Rofl ...... !!

我沒有把節目放在控制器中。因此,只有這些線具有在所述控制器和所述視圖被添加如下:

在控制器

@images = Image.all 

在View

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

由於