私はActivitiesControllerでこれを設定しました:
class ActivitiesController < ApplicationController
def index
following_ids = current_member.following_members.map(&:id)
@activities = Activity.where("member_id in (?)", following_ids.push(current_member.id)).order("created_at desc")
end
end
これは私のFollowsControllerで設定されています:
def create
@member = Member.find_by_user_name(params[:member_id])
@follow_member = current_member.follow(@member)
if @follow_member
current_member.create_activity(@follow_member, 'followed')
respond_to do |format|
format.html { redirect_to @member }
format.js
end
end
end
そして、これは別のメンバーをフォローするアクティビティを表示するように設定します:
<div>
<span class="status_name">
<%= link_to activity.member.user_name, profile_path(activity.member) %>
</span>
<span>
is now following <%= link_to activity.targetable.following_member.user_name, "#" %>
</span>
<span class="meta">
<%= time_ago_in_words(activity.targetable.created_at) %>
</span>
</div>
<div class="act_content">
<%= follow_profile_link activity.targetable.following_member %>
</div>
次のアクションを取得して、フィードに新しいアクティビティ アイテムを作成することはできましたが、フォローされているメンバーに電話をかける方法がわかりません。次のエラーが表示されます。
undefined method `following_member' for #<Follow:0x835b150>
app/views/activities/follow/_followed.html.erb:3:in `_app_views_activities_follow__followed_html_erb__269116874_68857716'
app/views/activities/index.html.erb:14:in `block in _app_views_activities_index_html_erb___16061925_44845644'
app/views/activities/index.html.erb:5:in `_app_views_activities_index_html_erb___16061925_44845644'
私は何をする必要があるか、またはこれを機能させるために具体的に何を呼び出すべきかを理解できません。何か案は?
編集 - モデル
活動モデル
class Activity < ActiveRecord::Base
belongs_to :member
belongs_to :targetable, polymorphic: true
end
モデルに従う
class Follow < ActiveRecord::Base
extend ActsAsFollower::FollowerLib
extend ActsAsFollower::FollowScopes
# NOTE: Follows belong to the "followable" interface, and also to followers
belongs_to :followable, :polymorphic => true
belongs_to :follower, :polymorphic => true
def block!
self.update_attribute(:blocked, true)
end
end
会員モデル
class Member < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :email_confirmation, :password, :password_confirmation, :remember_me,
:first_name, :last_name, :user_name, :pursuits, :avatar, :bio, :city, :state, :country, :pursuit_list
has_many :medium
has_many :statuses
has_many :activities
acts_as_follower
acts_as_followable
acts_as_ordered_taggable
acts_as_ordered_taggable_on :pursuits
def create_activity(item, action)
activity = activities.new
activity.targetable = item
activity.action = action
activity.save
activity
end
編集 - アクティビティの移行
class CreateActivities < ActiveRecord::Migration
def change
create_table :activities do |t|
t.integer :member_id
t.string :action
t.integer :targetable_id
t.string :targetable_type
t.timestamps
end
add_index :activities, :member_id
add_index :activities, [:targetable_id, :targetable_type]
end
end
活動指数
<% @activities.each do |activity| %>
<div class="status">
<div class="row">
<div class="span1 stream_av">
<%= avatar_profile_link activity.member %>
</div>
<div class="span7">
<%= render partial: "activities/#{activity.targetable_type.underscore}/#{activity.action}",
locals: { activity: activity } %>
</div>
</div>
</div>
<% end %>
メディアをアップロードするための新しいアクティビティ
<div>
<span class="status_name">
<%= link_to activity.member.user_name, profile_path(activity.member) %></span> <span>uploaded new <%= link_to "Media", profile_media_path(activity.member) %></span> <span class="meta"> <%= time_ago_in_words(activity.targetable.created_at) %>
</span>
</div>
<div class="act_content">
<%= link_to image_tag(activity.targetable.asset.url(:medium), class: ''), medium_path(activity.targetable_id) %>
</div>
ステータスを書き込むための新しいアクティビティ
<div>
<span class="status_name">
<%= link_to activity.member.user_name, profile_path(activity.member) %></span> <span>wrote a <%= link_to "Post", profile_stream_path(activity.member) %></span> <span class="meta"> <%= time_ago_in_words(activity.targetable.created_at) %>
</span>
</div>
<div class="act_content">
<%= activity.targetable.content %>
</div>