Friday, 15 February 2013

undefined method `reverse' in Ruby on Rails - displaying data in a table -


I am trying to show all examples of model 'project' in a table using the following code:

  & lt; Table style = "table-layout: fixed;" & Gt; & Lt;% @ projects.each.reverse do | Project | & Gt%; & Lt; TR & gt; & Lt; Td style = "width: 10%;" & Gt; & Lt;% = link_to project.owner.upcase, user_path (project.owner)% & gt; & Lt; / TD & gt; & Lt; Td> & Lt;% = link_to project.title, project_path (project)% & gt; & Lt; / Td> & Lt; Td style = "" & gt; & Lt;% = project.comments.pluck (: body) .last Project.descr% & gt; & Lt; / Td> & Lt; Td> & Lt;% = project.sdate.strftime ('% d /% m /% y')%> & Lt; / Td> & Lt; Td> & Lt;% = project.comments.pluck (: expdate) .last.try (: strftime, '% d /% m /% Y') || Project.edate.strftime ('% d /% m /% y')%> & Lt; / Td> & Lt; TD & gt; & Lt;% = link_to 'Edit', edit_project_path (project)% & gt; & Lt; Br> & Lt;% = link_to 'Delete', project_path (project), method :: delete, data: {confirm: 'are you sure?' }% & Gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt;% end% & gt; & Lt; / Table & gt;  

But I am getting this error:

NoMethodError in Projects # index

Undefined method For reverse # & lt; Enumanner: 0x44bc9c8 & gt;

Can anyone make a mistake?

I have used a similar line elsewhere, and it worked fine:

   ;  

Thanks advance!

You're trying to reverse the collection of personal items instead.

As Aswin said: reverse before every instead of @ projects.reverse.each .


No comments:

Post a Comment