I am using Rails 4, and trying to upload an image and then store it after processing it.
I am using just one view, where I want the user to upload the image, I process the image, store it in db, and then reload the page with the new processed image.
My model (user.rb)
class User < ActiveRecord::Base
mount_uploader :image, ImageUploader
end
Uploader (image_uploader.rb)
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process :changeImage
def changeImage
manipulate! do |source|
source = source.sepiatone
end
end
Controller (app_main_controller.rb)
require 'Rmagick'
class AppMainController < ApplicationController
def index
# page reload handling when the file uploads
if(params.has_key?("file-input"))
@u= User.new
@u.image = params["file-input"]
if(@u.save)
render js: "alert('SAVED')"
else
render js: "alert('Error while saving image! Try Again!')"
end
# initial page load
else
end
end
end
I access the image-uploader in my view (i.e. index) with image_tag @u.image_url
I keep on getting "stack level too deep" everytime I add any kind of processing in image_uploader.rb. If no processing is added, the image gets uploaded fine.
Any ideas, anyone?