0
我正在學習導軌,目前我正在跟隨Mattan Griffel的'One Mont Rails'。我花了很多時間尋找這個答案,並嘗試了一切,但似乎沒有任何工作。我使用回形針寶石來上傳圖片,但上傳後,圖片不顯示。唯一顯示的是缺失的圖像圖標。有人可以請幫忙。非常感謝。Rails 4 - 回形針不顯示上傳的圖像
這裏是我的GitHub庫的鏈接:github.com/robertguss/omrails
銷控制器:pins_controller.rb
class PinsController < ApplicationController
respond_to :html, :xml, :json
before_filter :authenticate_user!, except: [:index]
before_action :set_pin, only: [:show, :edit, :update, :destroy]
def index
@pins = Pin.all
respond_with(@pins)
end
def show
respond_with(@pin)
end
def new
@pin = current_user.pins.new
respond_with(@pin)
end
def edit
@pin = current_user.pins.find(params[:id])
end
def create
@pin = current_user.pins.new(pin_params)
@pin.save
respond_with(@pin)
flash[:success] = "Pin was created successfully!"
end
def update
@pin = current_user.pins.find(params[:id])
@pin.update(pin_params)
respond_with(@pin)
flash[:success] = "Pin was updated successfully!"
end
def destroy
@pin = current_user.pins.find(params[:id])
@pin.destroy
respond_with(@pin)
flash[:alert] = "Pin was deleted!"
end
private
def set_pin
@pin = Pin.find(params[:id])
end
def pin_params
params.require(:pin).permit(:description)
end
end
銷型號= pin.rb
class Pin < ActiveRecord::Base
validates :user_id, presence: true
validates :description, presence: true
has_attached_file :image,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename"
validates_attachment :image, content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png' 'image/gif'] },
size: { less_than: 5.megabytes }
belongs_to :user
end