I'm getting NoMethodError at /article
undefined method 'article_category' for Mongoid::Criteria
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
Article_category controller
class ArticleCategoriesController < ApplicationController
def category # Give the view all categories to list
@categories = ArticleCategory.order("created_at DESC")
end
def show
@category = ArticleCategory.find(params[:id])
end
end
routes
get 'article', to: 'articles#article'
get 'article/:id', to: 'articles#view_article', as: 'view_article'
resources :article_categories do
resources :articles, shallow: true
end
Is there everything good with my category controller ?
In my article view i'm displaying it in this way.
<%= link_to @article.article_category.name, @article.article_category -%>