1
我創建了一個用戶幫手,像這樣:asset_path在自定義類
module UserHelper
def user_photo user, size = 30
image_tag user_avatar_url(user, size), :height => size, :width => size, :title => user_name(user), :alt => '' if user
end
alias :user_avatar :user_photo
def user_avatar_url user, size = 30
user.image ? user.image.thumb("#{size}x#{size}#").url : asset_path('icons/unknown-user-icon.png')
end
end
但是,我得到一個錯誤:
undefined method `asset_path' for #<UserProfileHtmlTemplater:0x0000000680aad8>
目前,我有以下幾點:
class UserProfileHtmlTemplater < CompanyTextTemplater
include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::OutputSafetyHelper
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::TagHelper
include UserHelper
....
def prepare_locals_for(user)
Hash.new.tap do |locals|
locals[:first_name] = user.first_name
locals[:last_name] = user.last_name
locals[:email] = user.email
locals[:photo] = raw user_photo(user, '200x200>')
user.profile.visible_fields.each do |field|
locals[field.label] = field.value
end
end
end
asset_path是您定義的方法嗎?它不在[Rails API文檔](http://api.rubyonrails.org/)中。 –
不,這是鏈輪的東西 – Vladimir