I am using these gem's to handle my image uploader:
gem 'carrierwave'
gem 'mini_magick'
gem 'fog'
However I can't seem to find out whether or not the image is nil or empty, as it can't be because it returns this when I call @user.picture:
"********@hotmail.co.uk", encrypted_password:
"************************************", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 6, current_sign_in_at: "2016-03-18 11:23:00", last_sign_in_at: "2016-03-18 11:18:16", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2016-03-17 15:00:46", updated_at: "2016-03-18 11:24:13", provider: nil, uid: nil, username: "StormViper", login: nil, cart_id: 1, admin: true, picture: "download.jpg", brand_id: 1, is_brand?: true>, @mounted_as=:picture, @storage=#>, @file=#, @versions={}>
This is my user controller:
if @user.save
p "USER SAVED LOGIN: #{@user.username}"
@cart = Cart.create(:user_id => @user.id, :cart_count => 0)
@cart.save
@user.cart_id = @cart.id
@user.save
@slot = Slot.create(:cart_id => @cart.id)
@slot.save
@cart.slot_id = @slot.id
@cart.save
redirect_to root_path
else
p "USER FAILED LOGIN: #{@user.username}"
render 'new'
end
How would I solve this issue? I can't directly change the picture.url as it returns:
*** NoMethodError Exception: undefined method `url=' for
PictureUploader:0x007f73e6135e78>
My user model contains:
class User < ActiveRecord::Base
has_one :cart
has_many :slots, through: :carts
belongs_to :brand
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
attr_accessor :login
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:authentication_keys => [:login]
validates :username, presence: true, uniqueness: true
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions.to_hash).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
elsif conditions.has_key?(:username) || conditions.has_key?(:email)
where(conditions.to_hash).first
end
end
mount_uploader :picture, PictureUploader
end
User
model? Can you update your post with that info? – flanger001