Все, я в настоящее время изучаю Rails и продолжаю проект, и я сталкиваюсь с проблемой. Я не могу показать изображение пользователя, которому принадлежит сообщение к.Как показать gravatar пользователя, который следит за Rails
Когда я иду на домашнюю страницу, я должен видеть сообщение пользователей, за которыми вы следуете ... и, к сожалению, я не уверен, как я могу показать изображение пользователя, которому принадлежит сообщение .... я могу показать их сообщение, но не уверен, как я показываю их образ. Должен сказать, я использую драгоценный камень скрепки.
модель пользователя
class User < ActiveRecord::Base
# Include по умолчанию разработать модули. Другие доступны: #: Подтверждаемый,: lockable,: timeoutable и: omniauthable devise: database_authenticatable,: registerable, : recoverable,: rememberable,: trackable,: validatable has_attached_file: avatar,: styles => {: medium = > "300x300>",: thumb => "100x100 #"},: default_url => "/images/:style/missing.png" validates_attachment_content_type: avatar,: content_type => /\Aimage/.*\Z/
has_many :followeds, through: :relationships
has_many :relationships, foreign_key: "follower_id", dependent: :destroy
has_many :followed_users, through: :relationships, source: :followed
has_many :reverse_relationships, foreign_key: "followed_id"
has_many :reverse_relationships, foreign_key: "followed_id",
class_name: "Relationship",
dependent: :destroy
has_many :followers, through: :reverse_relationships, source: :follower
has_many:avatar, dependent: :destroy
has_many :posts, dependent: :destroy # remove a user's posts if his account is deleted.
has_many :active_relationships, class_name: "Relationship", foreign_key: "follower_id", dependent: :destroy
has_many :passive_relationships, class_name: "Relationship", foreign_key: "followed_id", dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
has_many :followers, through: :passive_relationships, source: :follower
def avatar_url
avatar.url(:medium)
end
# helper methods
# follow another user
def follow(other)
active_relationships.create(followed_id: other.id)
end
# unfollow a user
def unfollow(other)
active_relationships.find_by(followed_id: other.id).destroy
end
# is following a user?
def following?(other)
following.include?(other)
end
end
я могу получить текущий пользовательский файл, но если я войти в свой аккаунт, и я слежу за кого-то, я хочу, чтобы их изображение не мое для связанных с ними пост ..
<%=image_tag(current_user.avatar.url, class: "img-circle img-responsive img-raised", :size => "100x100") %>
Это работает !! Большое вам спасибо за ответ! –