How do I show my profile pictures with action feeds?

How can we include Facebook profile pictures in Activity_controller (aka news)?

class ActivitiesController < ApplicationController
    def index
      @activities = PublicActivity::Activity.order("created_at desc").where(owner_id: current_user.following_ids, owner_type: "User")
    end
end

      

I am getting profile pictures from user.rb :

def self.from_omniauth(auth)
  where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user|
    user.provider = auth.provider
    user.image = auth.info.image #specifically this line &
    user.uid = auth.uid          #specifically this line
    user.name = auth.info.name
    user.oauth_token = auth.credentials.token
    user.oauth_expires_at = Time.at(auth.credentials.expires_at)
    user.password = (0...8).map { (65 + rand(26)).chr }.join
    user.email = (0...8).map { (65 + rand(26)).chr }.join+"@mailinator.com"
    user.save!
  end
end

      

activity index

<% @activities.each do |activity| %>
    <% if @user.uid %>
    <%= image_tag @user.image %>
  <% else %>
    <%= gravatar_for @user %>
  <% end %>
    <%= link_to activity.owner.name, activity.owner if activity.owner %>
    <%= render_activity activity %>
<% end %>

      

I am currently getting this error: undefined method 'uid' for nil:NilClass

Thanks for your experience!

+3


source to share


1 answer


It seems @user is not assigned in the ActivityController's index function. If there is a relationship between activity and user, you can do it like this:



<% @activities.each do |activity| %>
    <% if activity.user.uid %>

      

+3


source







All Articles