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?
:pathand/or:urlas explained here to make sure you know where it is trying to save the uploads - hunteros:path => ":rails_root/public/system/:class/:attachment/:style/:filename"and:url => "/system/:class/:attachment/:style/:filename". Changing:imageto:attachmentand getting rid of:id_partitionwill clean up the path a little bit. For:url, start your path with the/systemrather than:rails_root- hunterosimage_file_name, etc). I believe Paperclip only shows the default image if those are blank; otherwise it will use the specified url, even if it doesn't exist at the specified path (it will just show a broken image in that case, not the default) - hunteros