, j'apprends actuellement Rails et d'entreprendre un projet et je suis en cours d'exécution dans un issue.I suis incapable de montrer l'image de l'utilisateur qui appartient le poste à.Comment afficher le gravatar de l'utilisateur qui suit dans Rails
Quand je vais à la page d'accueil, je devrais voir le poste des utilisateurs que vous suivez ... et malheureusement je ne suis pas sûr comment je peux montrer l'image de l'utilisateur à qui appartient le poste .... Je peux montrer leur poste, mais je ne sais pas comment je montre leur image. Je dois dire que j'utilise un trombone.
modèle utilisateur
class User < ActiveRecord::Base
# include par défaut des modules concevoir. Les autres disponibles sont: #: confirmable,: verrouillable,: timeoutable et: omniauthable legs: database_authenticatable,: enregistrable, : récupérable,: rappelable,: traçable,: validable has_attached_file: avatar,: styles => {: medium = > "300x300>",: pouce => "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
je peux obtenir l'image de l'utilisateur actuel, mais si je me connecte à mon compte, et je suis suivre quelqu'un, je veux voir leur image pas à moi pour leur poste associé ..
<%=image_tag(current_user.avatar.url, class: "img-circle img-responsive img-raised", :size => "100x100") %>
Cela fonctionne !! Merci beaucoup pour la réponse! –