0

所以我正在尝试关注 railscast(#182 修订版)& JCrop 似乎对我不起作用。我不确定它是否与我的 RMagick 或 Imagemagick 安装有关,或者我只是缺少教程中的某些内容。我在网上搜索过类似的问题,但似乎无法找到解决我做错了什么的方法。当我创建一个新的调查时,我添加了一张图片,点击保存,然后它会将我带到裁剪屏幕。当我单击裁剪时,出现以下错误:

ArgumentError in Investigations#show

Showing /Users/bbarton250/Documents/app/app/views/investigations/show.html.erb     where line #8 raised:

Version cover doesn't exist!
Extracted source (around line #8):

   <div id="aboutus">
       <div class="container">
         <div class="padd" style="padding: 0px 0px 10px 10px">
           <div class="section_header cover_art" style="background: url('<%=       @investigation.investigationimage_url(:cover).to_s %>') no-repeat;">
             <div class="whitetitle">
               <h3><%= @investigation.title %></h3>
               <%= render 'shared/investigationstats' %>
 Rails.root: /Users/bbarton250/Documents/app

Application Trace | Framework Trace | Full Trace
app/views/investigations/show.html.erb:8:in      `_app_views_investigations_show_html_erb___1313059905282739098_70290275302200'
Request

 Parameters:

 {"id"=>"82"}

任何帮助将不胜感激...谢谢

我的 CROP.HTML.ERB 文件

<div class="row-fluid">
  <div id="aboutus">
    <div class="container">
      <div class="padd" style="padding:30px 10px 10px 10px">
        <div class="section_header">

          <div class="row-fluid">
            <h3>Crop Investigation Cover Image</h3>
          </div><br/>
            <div class="row-fluid">
            <%= image_tag @investigation.investigationimage_url(:profile), id: "cropbox" %>

            <%= form_for @investigation do |f| %>
              <% %w[x y w h].each do |attribute| %>
                <%= f.hidden_field "crop_#{attribute}" %>
              <% end %><br clear="all">
              <div class="actions">
                <%= f.submit "Crop" %>
              </div>
             <% end %>
          </div>

        </div>
      </div>
    </div>
  </div>
</div>

我的宝石档案

source 'https://rubygems.org'

gem 'rails'
gem 'bootstrap-sass'
gem 'bcrypt-ruby'
gem 'will_paginate'
gem 'bootstrap-will_paginate'

gem "rmagick"
gem 'carrierwave'
gem 'auto_html'

调查模型

class Investigation < ActiveRecord::Base

  attr_accessible :title, :content, :investigationimage, :user_id, :crop_x, :crop_y,   :crop_w, :crop_h
  validates :title, presence: true, length: { maximum: 140 }
  validates :content, presence: true
  validates :investigationimage, presence: true
  mount_uploader :investigationimage, ImageUploader
  attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
  after_update :crop_investigationimage

  def crop_investigationimage
    investigationimage.recreate_versions! if crop_x.present?
  end

  default_scope -> { order('created_at DESC') }
end

INVESTIGATIONIMAGE_UPLOADER.RB

# encoding: utf-8

class InvestigationimageUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
  storage :file
  # storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url
  #   # For Rails 3.1+ asset pipeline compatibility:
  #   # ActionController::Base.helpers.asset_path("fallback/" + [version_name,     "default.png"].compact.join('_'))
  #
  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  # end

  # Process files as they are uploaded:
  # process :scale => [200, 300]
  #
  # def scale(width, height)
  #   # do something
  # end

  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_limit => [100, 100]
  end

  version :profile do
    process :resize_to_limit => [1400, 300]
  end

  version :search do
    process :resize_to_limit => [200, 150]
  end

  version :cover do
    process :crop
    resize_to_fill(1400, 300)
  end

  def crop
    if model.crop_x.present?
      resize_to_limit(1400, 300)
      manipulate! do |img|
        x = model.crop_x.to_i
        y = model.crop_y.to_i
        w = model.crop_w.to_i
        h = model.crop_h.to_i
        img.crop!(x, y, w, h)
      end
    end
  end

end

INVESTIGATIONS.JS.COFFEE JAVASCRIPT 文件

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
jQuery ->
  new InvestigationImageCropper()

class InvestigationImageCropper
  constructor: ->
    $('#cropbox').Jcrop
      aspectRatio: 24/9
      setSelect: [0,0,1400,300]
      onSelect: @update
      onChange: @update

  update: (coords) =>
    $('#investigation_crop_x').val(coords.x)
    $('#investigation_crop_y').val(coords.y)
    $('#investigation_crop_w').val(coords.w)
    $('#investigation_crop_h').val(coords.h)

调查负责人

class InvestigationsController < ApplicationController
  before_filter :signed_in_user, only: [:create, :new, :edit, :update, :followers]

  def new
    @investigation = Investigation.new
  end

  def show
     @investigation = Investigation.find(params[:id])
  end

  def index
    @investigations = Investigation.paginate(page: params[:page])
  end

  def create
    @investigation = Investigation.new(params[:investigation])
    if @investigation.save
      if params[:investigation][:investigationimage].present?
        render :crop
      else
        flash[:success] = "You've successfully created an Investigation..."
        redirect_to @investigation
      end
    else
      render 'new'
    end
  end

  def edit

  end

  def update
    @investigation = Investigation.find(params[:id])
    if @investigation.update_attributes(params[:investigation])
      if params[:investigation][:investigationimage].present?
        render :crop
      else
        flash[:success] = "Investigation Created"
        redirect_to @investigation
      end
    else
      render 'edit'
    end
  end

  def destroy
    User.find(params[:id]).destroy
    flash[:success] = "Investigation destroyed"
    redirect_to users_path
  end

  def followers
      @title = "Following this Investigation"
      @investigation = Investigation.find(params[:id])
      @investigations = @investigation.followers.paginate(page: params[:page])
      render 'show_follow_investigation'
  end

end

SHOW.HTML.ERB(调查资料)

<% provide(:title, @investigation.title) %>

<div class="row-fluid">

  <div id="aboutus">
      <div class="container">
        <div class="padd" style="padding: 0px 0px 10px 10px">
          <div class="section_header cover_art" style="background: url('<%= @investigation.investigationimage_url(:cover).to_s %>') no-repeat;">
            <div class="whitetitle">
              <h3><%= @investigation.title %></h3>
              <%= render 'shared/investigationstats' %>
            </div>
          </div>
        </div>
      </div>
  </div>

</div>

感谢帮助!

4

1 回答 1

1

models/investigation.rb第 7 行

mount_uploader :investigationimage, ImageUploader

应该

mount_uploader :investigationimage, InvestigationimageUploader

希望有帮助

于 2013-10-21T08:37:39.523 回答