作为一个Rails新手,我遇到了一个我无法弄清楚的问题。我目前正在使用Devise进行身份验证,使用Paperclip进行附件。我已成功将上传字段添加到用户编辑中,并且图像已成功保存。
我目前的设置是我有一个带有默认徽标的标题。我正在尝试创建一个检查用户是否有徽标的调用。
申请助手:
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
我收到错误声明 NO HANDLER 未定义的方法
我如何基本上检查用户是否已上传徽标并显示该显示而不是默认?
TIA!
答案 0 :(得分:2)
我在logo_for
方法中看到了一些错误。
尝试将user.logo.present?
更改为user.logo?
,这是Paperclip提供的功能(我相信)。此外,您的第一个image_tag
参考文献应如下所示:
image_tag user.logo.url(:small)
,请注意我删除了下划线。