Question

I'm adding cropping functionality to my Rails app and am using the Railscast as my guide: http://railscasts.com/episodes/182-cropping-images-revised

I've double checked things and am still getting a strange error when I try to load any page. Here is the message I'm getting:

SyntaxError in PeopleController#show
/app/uploaders/photo_uploader.rb:40: syntax error, unexpected '(', expecting keyword_end process :resize_to_limit(600, 600) ^ 
/app/uploaders/photo_uploader.rb:80: syntax error, unexpected end-of-input, expecting keyword_end

Extracted source (around line #4):

validates_presence_of :fname, :lname, :company, :department, :title, :work_phone, :mobile, :office, :address, :city, :state, :zipcode, :country, :suite, :column

mount_uploader :photo, PhotoUploader

after_update :crop_photo

Here is my person model code:

class Person < ActiveRecord::Base
validates_presence_of :fname, :lname, :company, :department, :title, :work_phone, :mobile, :office, :address, :city, :state, :zipcode, :country, :suite, :column

mount_uploader :photo, PhotoUploader

after_update :crop_photo


  def crop_photo
    photo.recreate_versions! if crop_x.present?
  end
end

Here is my photo uploader code:

# encoding: utf-8

class PhotoUploader < 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

 include CarrierWave::MimeTypes
 process :set_content_type

# 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 :large do
  process :resize_to_limit => [600, 600]
end

version :thumb do
  process :crop
  process :resize_to_limit => [200, 200]
end

def crop
  if model.crop_x.present?
    resize_to_limit(600, 600)
    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

after :store, :remove_original_file

def remove_original_file(p)
  if self.version_name.nil?
    self.file.delete if self.file.exists?
  end
end

# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
#   %w(jpg jpeg gif png)
# end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
#   "something.jpg" if original_filename
# end

end

Here is what I have added for my Create section of my controller:

if @person.save
  if params[:person][:photo].present?
    render :crop
  else
    redirect_to @user, notice: "Successfully created user."
  end
end

I have similar code in my New action in my controller.

I'm completely stumped. The number of "End"s seem to match up from what I've seen.

I'm on Rails 4, Ruby 2 and am using Bootstrap 2.

All help is greatly appreciated.

Était-ce utile?

La solution

version :large do
  process :resize_to_limit(600, 600)
end

should be:

version :large do
  process :resize_to_limit => [600, 600]
end
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top