Я делаю список дел, где я могу иметь несколько списков с различными задачами.Моя главная проблема - когда я пытаюсь создать функцию избранного, где я могу добавить списки в свой список избранного.
Модель списка
class List < ApplicationRecord
belongs_to :user
has_many :tasks
has_many :favorites
has_many :favoriters, through: :favorites, foreign_key: :user_id
accepts_nested_attributes_for :tasks, allow_destroy: true
end
Модель избранного
class Favorite < ApplicationRecord
belongs_to :list
belongs_to :user
end
Модель пользователя
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :lists
has_many :favorites
has_many :favorite_lists, through: :favorites
end
Списки контроллеров:
def favorites
@list = List.find(params[:list_id])
current_user.favorites << @list
redirect_to lists_path, notice: 'Added to Favorite List'
end
Маршруты:
resources :lists do
resources :tasks, only: [:index, :new, :create]
post :favorites
end
Link_to в моем представлении списка просмотра:
<%= link_to "Favorite", list_favorites_path(@list), method: :post %>
Сообщение об ошибке:
Favorite(#70365311619800) expected, got #<List id: 1, user_id: 1, public: true, created_at: "2019-05-02 00:43:05", updated_at: "2019-05-02 00:43:05", title: "teste", favorite: nil> which is an instance of List(#70365317909860)
Что мне здесь не хватает?