I’m having some issues trying to get the top 5 of my tutorial model to display on my index page.
I’ve got the following in the index method (for the index action) in my tutorial controller:
@TopTutorials = Tutorial.find(:all, :order => "views DESC", :limit => 5)
I then use this instance variable and try to loop through the top 5 in my index view:
<% @TopTutorials.each do |TopViewedTutorial| %>
<%= link_to TopViewedTutorial.name, show_tutorial_path(TopViewedTutorial.category_id, TopViewedTutorial.to_param) %>
<% end %>
I’m kind of new to looping through things like this and so I assume I’ve done something wrong. On loading up the index page I get the following error at the “.each do” line:
formal argument cannot be a constant
Could anyone help me out with this?
Best Regards,
Joe
You have to change TopViewedTutorial to something starting with lowercase letter like topViewedTutorials. You could read more about ruby names here http://rubylearning.com/satishtalim/ruby_names.html.