NoMethodError, undefined method in my controller Ruby on Rails -
i'm getting nomethoderror @ /article
undefined method 'article_category' 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 view categories list @categories = articlecategory.order("created_at desc") end def show @category = articlecategory.find(params[:id]) end end
routes
'article', to: 'articles#article' 'article/:id', to: 'articles#view_article', as: 'view_article' resources :article_categories resources :articles, shallow: true end
is there category controller ?
in article view i'm displaying in way.
<%= link_to @article.article_category.name, @article.article_category -%>
your problem in articlescontroller#article
:
def article @article = article.order_by(created_at: 'desc').page params[:page] end
that sequence of order_by
, page
calls building query have mongoid::criteria
in @article
rather single article
instance template apparently expects.
i'm not sure presence of view_article
, article/:id
route suggests article
method should like:
def article @articles = article.order_by(created_at: 'desc').page params[:page] # ------^ end
and corresponding view should iterate on @articles
display each article.
Comments
Post a Comment