0

始める前に、提供された複数のソリューションをググって試してみたことをお伝えしたいと思います。私はまだ同じ問題に遭遇しています。

ペーパークリップを使用して画像をアップロードすると、壊れた画像が表示されます。右クリックして調べたところ、ページが上がってエラーが発生していることがわかりました: Get http://localhost:3000/system/pins/images/000/000/008/medium/imgres.jpg 404 (Not Found)。

意見

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

<% if @pin.user == current_user %>
<%= link_to 'Edit', edit_pin_path(@pin) %> 
<%= link_to 'Back', pins_path %>
<% end %>

モデル

class Pin < ActiveRecord::Base
    belongs_to :user
    has_attached_file :image, :styles => { :medium => "300x300>", :thumb =>         "100x100>" }
    validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
end

コントローラ

class PinsController < ApplicationController
  before_action :set_pin, only: [:show, :edit, :update, :destroy]
  before_action :correct_user, only: [:edit, :update, :destroy]
  before_action :authenticate_user!, except: [:index, :show]

  def index
    @pins = Pin.all
  end

  def show
  end

  def new
    @pin = current_user.pins.build
  end

  def edit
  end

  def create
    @pin = current_user.pins.build(pin_params)
    if @pin.save
      redirect_to @pin, notice: 'Pin was successfully created.'
    else
      render :new
    end
  end

  def update
    if @pin.update(pin_params)
      redirect_to @pin, notice: 'Pin was successfully updated.'
    else
      render :edit
    end
  end

  def destroy
    @pin.destroy
    redirect_to pins_url
  end

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

    def correct_user
      @pin = current_user.pins.find_by(id: params[:id])
      redirect_to pins_path, notice: "Not authorized to edit this pin" if     @pin.nil?
    end

    # Never trust parameters from the scary internet, only allow the white     list through.
    def pin_params
      params.require(:pin).permit(:description, :image)
    end
end

Gemfile

source 'https://rubygems.org'
ruby '2.2.6'


gem 'rails', '4.0.0'

gem 'sass-rails', '~> 4.0.0'

gem 'uglifier', '>= 1.3.0'

gem 'coffee-rails', '~> 4.0.0'

gem 'jquery-rails'

gem 'turbolinks'

gem 'jbuilder', '~> 1.2'

gem 'coffee-script-source', '1.8.0'

gem 'bootstrap-sass'

gem 'devise'

gem 'paperclip', '~> 4.2.0'

group :development, :test do
gem 'sqlite3' 
end

group :production do
    gem 'pg'
    gem 'rails_12factor'
end

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

gem ファイルのダウングレードとアップグレード、コカイン gem の追加、モデルへの :path => "" および :url => "" の追加、タイムスタンプの false への設定、コンピューターとサーバーの再起動、アンインストールと再インストールを試みました。 imagemagick、file.exe を手動でダウンロードし、指示に従ってコードを development.rb に調整し、イメージの場所を変更します。何時間もグーグルで検索して調整しているため、試したことを忘れている可能性があります。助けてくれる人はいますか?

4

1 に答える 1