2015-06-18 103 views
0

所以我試圖讓一個基本的carrierwave上傳爲攝影網站工作。Rails Carrierwave上傳不上傳

我去了,並生成一個腳手架,並得到了上傳所有設置。頁面加載顯示上傳框,它看起來像我上傳一張照片,但當我去顯示頁面時,它吐出類似Image: #<ActionDispatch::Http::UploadedFile:0x007fa03f7389a8>,並沒有顯示圖像。

我還是新來的鐵軌,所以有可能是非常簡單的,我沒有看到這裏。

謝謝!

這裏被稱爲我的上傳image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base 
include CarrierWave::RMagick 
    storage :file 
    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 
    version :thumb do 
    process :resize_to_limit => [200, 200] 
    end 
end 

這裏是我的show.html.rb

<p id="notice"><%= notice %></p> 

<p> 
    <strong>Title:</strong> 
    <%= @image.title %> 
</p> 

<p> 
    <strong>Description:</strong> 
    <%= @image.description %> 
</p> 

<p> 
    <strong>Tag:</strong> 
    <%= @image.tag %> 
</p> 

<p> 
    <strong>Image:</strong> 
    <%= @image.image %> 
</p> 

<%= link_to 'Edit', edit_image_path(@image) %> | 
<%= link_to 'Back', images_path %> 

,這是我的圖片控制器

class ImagesController < ApplicationController 
    before_action :set_image, only: [:show, :edit, :update, :destroy] 

    # GET /images 
    # GET /images.json 
    def index 
    @images = Image.all 
    end 

    # GET /images/1 
    # GET /images/1.json 
    def show 
    end 

    # GET /images/new 
    def new 
    @image = Image.new 
    end 

    # GET /images/1/edit 
    def edit 
    end 

    # POST /images 
    # POST /images.json 
    def create 
    @image = Image.new(image_params) 

    respond_to do |format| 
     if @image.save 
     format.html { redirect_to @image, notice: 'Image was successfully created.' } 
     format.json { render :show, status: :created, location: @image } 
     else 
     format.html { render :new } 
     format.json { render json: @image.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # PATCH/PUT /images/1 
    # PATCH/PUT /images/1.json 
    def update 
    respond_to do |format| 
     if @image.update(image_params) 
     format.html { redirect_to @image, notice: 'Image was successfully updated.' } 
     format.json { render :show, status: :ok, location: @image } 
     else 
     format.html { render :edit } 
     format.json { render json: @image.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # DELETE /images/1 
    # DELETE /images/1.json 
    def destroy 
    @image.destroy 
    respond_to do |format| 
     format.html { redirect_to images_url, notice: 'Image was successfully destroyed.' } 
     format.json { head :no_content } 
    end 
    end 

    private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_image 
     @image = Image.find(params[:id]) 
    end 

    # Never trust parameters from the scary internet, only allow the white list through. 
    def image_params 
     params.require(:image).permit(:title, :description, :tag, :image) 
    end 
end 
+0

你需要使用IMAGE_TAG顯示圖像<%= IMAGE_TAG @ image.image_url%> –

+0

顯示你的模型,並形成以及這樣我就可以有一個也看看那個。 –

回答

0

試着改變你的show.html.erb

來自:

<p> 
    <strong>Image:</strong> 
    <%= @image.image %> 
</p> 

到:

<p> 
    <strong>Image:</strong> 
    <%= image_tag @image.image %> 
</p> 
+0

那麼,這改變了我在展會頁面上看到的樣子。現在它顯示了一個破碎的圖像鏈接,仍然顯示與我的第一篇文章相同類型的東西。 但是,當我進入我的上傳文件夾中似乎沒有任何東西,所以我不知道如何解決這個問題。 – djbartos93