How should I pass the params about the article category. I have a Article which belongs to Article category. When I click to this <%= link_to @article.name, article_categories_path%>
, I want to see the all articles in this category. So I have to pass the params through it to ArticleCategoryController. Is my link to statement correct ? Now I get a "Article" instead of the category name( when I click it I'm getting the error: Document.find expects the parameters to be 1 or more ids,
).
Article model
class Article
include Mongoid::Document
include Mongoid::Timestamps
field :title, type: String
field :content, type: String
belongs_to :user
#kategorie
belongs_to :article_category
Article controler
class ArticlesController < ApplicationController
def article
@article = Article.order_by(created_at: 'desc').page params[:page]
end
def view_article
@article = Article.find(params[:id])
end
end
ArticleCategory model
class ArticleCategory
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
has_many :articles
end
Routes
resources :article_categories do
resources :articles, shallow: true
end
ArticleCategories Controller
class ArticleCategoriesController < ApplicationController
def index
@category = ArticleCategory.find(params[:id])
@articles = @category.articles
end
end
Article view
<p>Category: <%= link_to @article.name, article_categories_path%>
Tagi: <%= link_to "Tagi", tags_path %> </p>