jeudi 26 février 2015

Rails need advise on controller practices

I try to follow RESTfull approach in controllers, but sometimes I need action which won't fit into default ones. E.g. I have an index action rendering all articles which is



def index
@articles = Article.all


but what if I also want search them? should I create separate actions for it, or should I bloat existing controller, like:



def index
if params[:search]
@articles = Article.where(id: params[:search_id])
else
@articles = Article.all


What is the right way?


Aucun commentaire:

Enregistrer un commentaire