###前提・実現したいこと
railsでpublic_activityを使って、お気に入りしているboardの
ユーザーのコメントが増えるごとにfeedしたいのですが、以下のエラーでつまづいてしまいます。
feed機能を使えるようにするにはどうしたらいいでしょうか
エラーコード
NameError in FavoritesController#index undefined local variable or method `favorite_ids' for #<FavoritesController:0x007faa0c36e8f0> Did you mean? favorites_url favorite_url favorites_path favorite_path @favorites @activities = PublicActivity::Activity.order(created_at: :desc).where(owner_id: favorite_ids, owner_type: "User")
###該当のソースコード
comment.rb
class Comment < ApplicationRecord include PublicActivity::Common end
comments_controller.rb
def create @comment = @message.comments.create(comment_params) @comment.user_id = current_user.id if @comment.save comment.create_activity :create, owner: current_user redirect_to message_path(@message) else render 'new' end end
favorites_controller.rb
def index @activities = PublicActivity::Activity.order(created_at: :desc).where(owner_id: favorite_ids, owner_type: "User") end
favorites/index.html.erb
<% @activities.each do |activity| %> <%= link_to activity.owner.name, activity.owner if activity.owner -%> <%= link_to activity.trackable.name, activity.trackable -%> <% end %>
favorite.rb
class Favorite < ApplicationRecord belongs_to :user belongs_to :message validates :user_id, :uniqueness => {:scope => :message_id} end
回答1件
あなたの回答
tips
プレビュー