Question

So I'm trying to follow a railscast (#182 Revised) & JCrop doesn't seem to be working for me. I'm not sure if its something with my RMagick or Imagemagick installation or if I'm just missing something from the tutorial. I've searched similar problems online and can't seem to find the solution for what I'm doing wrong. When I create a new investigation, I add an image, click save, then it takes me to the crop screen. When I click crop I get the following error:

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

Any help would be much appreciated...thx

MY CROP.HTML.ERB FILE

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

INVESTIGATION MODEL

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 CONTROLLER

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 (INVESTIGATION 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>

Appreciate the help!

Était-ce utile?

La solution

models/investigation.rb line #7

mount_uploader :investigationimage, ImageUploader

should be

mount_uploader :investigationimage, InvestigationimageUploader

Hope that helps

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top