Peege151
Peege151

Reputation: 1560

Paperclip Only Showing Default Image

Pretty new to ruby on rails and experimenting with some new gems.

So I have an issue with paperclip only loading the default image. No matter if I choose one or not.

Here is my code. Schema

create_table "users", force: true do |t|
t.string   "name"
t.string   "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string   "password_digest"
t.string   "remember_token"
t.boolean  "admin",              default: false
t.string   "image_file_name"
t.string   "image_content_type"
t.integer  "image_file_size"
t.datetime "image_updated_at"
end

user model:

has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" },      :default_url => "/images/emptyuser.png"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

call in the show.html.erb

      <p>
        <%= image_tag @user.image.url(:medium) %>
      </p>

user controller

  def create
@user = User.new(user_params)
if @user.save
  sign_in @user
 flash[:success] = "Welcome to My App?!"
  redirect_to @user
else
  render 'new'
end
end
def update
@user = User.find(params[:id])
if @user.update_attributes(user_params)
  flash[:success] = "Profile updated"
  redirect_to @user
else
  render 'edit'
end
    private

def user_params
  params.require(:user).permit(:name, :email, :password,
                               :password_confirmation, :image)
end

I'm pretty sure I had it working, and then when I added the default image I broke it, and now when I go back I can't get it to work..

Anyone know why my images aren't uploading and only the default url is being loaded?

I think I need some sleep. Sorry if this is a dumb fix, but I appreciate your help.

EDIT: Thanks for the link @hunteros I somehow missed that in the doc. It is being saved now to the default location. I will check to see if explicitly changing them does the trick.

EDIT#2: Would this be the proper syntax and pathing? Added to model user.rb

   :path  => ":rails_root/public/system/:class/:image/:id_partition/:style/:filename"
    :url => ":rails_root/public/system/:class/:image/:id_partition/:style/:filename"

The actual file structure is as follows: system/:class/images(is this :image?)/000(not sure here)/001/:style/actual file finally

Seems a little intense. Couldn't they just all go in one damn directory..?

:path  => ":rails_root/public/system/:class/:attachment/:style/:filename",
:url => "/system/:class/:attachment/:style/:filename"

when I call user.image I get the path, and it seems to match up but I still see default i mage. Image URL: /system/users/images/medium/sarahanddee.JPG?1394522170

are the numbers at the end of the string a problem?

Upvotes: 1

Views: 1165

Answers (2)

Peege151
Peege151

Reputation: 1560

I just had to remove the @ from @user.image.url

Upvotes: 0

Richard Peck
Richard Peck

Reputation: 76774

Firstly, never code when you're tired. It's my opinion that you must be well-rested in order to create truly efficient & compelling software

Secondly, you need to test your upload process to see if your image is being uploaded. If it's present in your db, the issue will be with how you're calling the image, else it will be a problem with the upload process

Your default_url looks fine to me - perhaps you could upload some logs of the requests your app is making each time it shows the "default" images?

Upvotes: 1

Related Questions