How can I display the details for a task in the same way (using my _task partial) whether the view is using @project.tasks (ie multiple) or just @task (ie individual task)?
My question is similar to this one : How can you make a ruby function accept either an individual item or collection of items and do the same thing?
I tried checking if @project.tasks.is_a? but it complained wrong number of arguments (0 for 1).
Any ideas?
I’m not sure what you want, but I understood that you want to render partial either collection on individual item. So if I right you should follow these steps and everything will work out of box. Let’s say you have model
Projectand ithas_manyTasks, the steps are:tasks/_task.html.erbprojects/show.html.erb) render like this:<%= render @project.tasks %><%= render @task %>Note: solution works for
Rails >= 3.