Привет, ребята, я пытаюсь добавить списки в свои коллекции. Я новичок в рельсах, любая помощь будет оценена по достоинству. В настоящее время я пытаюсь создать форму для создания нового списка, но новые/создать действия, похоже, испорчены.
Списки в конечном итоге будут жить в представлении коллекций позже через ajax.
В конечном итоге цель состоит в том, чтобы каждый пользователь владел несколькими коллекциями, и в каждой коллекции будет несколько списков, в каждом из которых будет несколько элементов.
Коллекции
class CollectionsController < ApplicationController
def index
@user = User.find(current_user)
@collection = Collection.where(:user_id => current_user.id)
end
def new
@collection = Collection.new
end
def show
@collection = Collection.find(params[:id])
@list = List.all
end
def create
@collection = Collection.new(collection_params)
@collection.user_id = current_user.id
# render :text => CGI.escapeHTML(@collection.inspect)
if @collection.save
redirect_to root_path(@user)
else
render 'new'
end
end
def edit
@collection = Collection.find(params[:id])
end
def update
if @collection.update(collection_params)
redirect_to root_path(@user)
else
render 'edit'
end
end
def destroy
@collection.destroy
redirect_to root_path(@user)
end
private
def collection_params
params.require(:collection).permit(:alias, :notes, :visibility)
end
def find_collection
@collection = @user.collection.find(params[:id])
end
end
Списки
class ListsController < ApplicationController
def index
@list = List.all
end
def new
@list = List.new
end
def create
@collection = Collection.find(params[:collection_id])
@list =
@collection.lists.create(comments_params)
if @collection.lists.save
redirect_to root_path(@user)
else
render 'new'
end
end
end
Пользователи
class UsersController < ApplicationController
def index
@user = User.find(current_user)
@collection = Collection.where(:user_id => current_user.id)
@user.collection = Collection.where(:user_id => current_user.id)
# render :text => CGI.escapeHTML(@collection.inspect)
end
end
Ссылка, которую я пытался
<%= link_to '<i class="fa fa-plus-square"></i> Add Subcategory'.html_safe, new_collection_list_path(@collection.id) %>
Текущие маршруты
devise_scope :user do
authenticated :user do
root 'collections#index', as: :authenticated
resources :collections do
resources :lists
end
end
Ошибка form_for
<%= form_for([@collection, @collection.lists.build]) do |f| %>
<% end %>
Модели
Users has_many :collections
Collections belong_to :user
has_many :lists
Lists belong_to :collection