As a Rails newbie, I am running into an issue in which I can not figure out. I am currently using Devise for authentication and Paperclip for attachments. I have successfully added an upload field to the user edit and the image saves successfully.
My current setup right now is I have a header with a default Logo. I am trying to create a call that checks for if user has logo.
Application Helper:
def logo_for(user)
if user_signed_in? && user.logo.present?
image_tag user.logo_url(:small)
else
image_tag("logo.png", :alt => "Sample App", :class => "round")
end
end
_header.html.erb
<%= link_to logo_for(@user), root_path %>
User.rb
has_attached_file :logo,
:styles => { :small => "150x150>" },
:url => "/images/logos/:id/:style/:basename.:extension",
:path => ":rails_root/public/images/logos/:id/:style/:basename.:extension",
:convert_options => { :all => "-auto-orient" }
attr_accessible :users, :logo, :logo_file_name, :logo_content_type, :logo_file_size, :logo_updated_at
end
I am receiving errors stating NO HANDLER undefined Method
How do I go about basically tapping into check if the user has uploaded a logo and have that display instead of default?
TIA!
I see a couple of things wrong in your
logo_formethod.Try changing
user.logo.present?touser.logo?which is functionality provided Paperclip (I believe). Furthermore, your firstimage_tagreference should read as follows:image_tag user.logo.url(:small), notice I removed the underscore.