2013-10-21 3 views
0

그래서 railscast (# 182 수정)를 따르려고합니다. & JCrop이 저에게 효과적이지 않은 것 같습니다. RMagick 또는 Imagemagick 설치가 필요한지 또는 튜토리얼에서 누락 된 부분이 있는지 확실하지 않습니다. 비슷한 문제를 온라인에서 검색해 보았고 내가 잘못하고있는 것에 대한 해결책을 찾지 못하는 것 같습니다. 새로운 조사를 만들 때 이미지를 추가하고 저장을 클릭하면 자르기 화면으로 이동합니다.JCrop 및 Carrierwave 이미지 자르기

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"} 

어떤 도움이 많이 주시면 감사하겠습니다 ... 들으

MY 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> 

MY GEMFILE

: 나는 작물을 클릭하면 나는 다음과 같은 오류가 발생합니다
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 FILE

# 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) 

INVESTIGATIONS 제어기

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 (조사 PROFILE)

<% 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> 

감사합니다.

답변

1

models/investigation.rb 라인 # 7

mount_uploader :investigationimage, ImageUploader 

을 행한 ... 굉장

+0

을하는 데 도움이

mount_uploader :investigationimage, InvestigationimageUploader 

희망해야한다. 멍청한 실수. 감사합니다. 이제 이미지의 '자르기'버전을 만듭니다. 때때로 빈 흰색 이미지를 자른 이미지로 만드는 이유를 알고 있습니까? (나는 그것이/내 다양한 ​​버전 및 크기 조정/크기 조정 문제가 있지만 완전히 확신 할 수있는 뭔가가 있다고 생각합니다). 자르기 영역을 선택하고 자르기를 클릭하면 자르기로 예정된 이미지 섹션 대신 빈 흰색 이미지가 생성됩니다. – BB500