Reputation: 2352
I've got a very weird scenario where it appears that a controller action method is being ignored in a rails app. I'm assuming this is not possible, but I need someone to help me see the "forest for the trees" :) Here is what I have. First a custom route:
match 'topusers/:skill', :to => 'skills#topusers', :as => :top_users
Then in my controller I have reduced it down to the following:class SkillsController < ApplicationController
class SkillsController < ApplicationController
....
def top_users
@skills = Skill.all
end
....
end
My view has been reduced to the following
<% @skills.each do |skill| %>
<%= skill.name %>
<% end %>
With this I receive an error of "undefined method `each' for nil:NilClass" on the @skills.each line. I know there is data in the skills table and I can see that via rails console. To troubleshoot I did a render :text => @skills.to_yaml and it appeared to be ignored. This confused me, so I then completely removed the top_users method and still got the same error which confused me because I thought rails would scream at me for not having a top_users method. I then thought that rails might be looking at a different controller, so I changed the name of my controller from SkillsController to SkillsXXXController. This time rails did yell at me telling it couldn't find the controller, so I know it was at least looking at the right controller.
So, any idea of why I am seeing this behavior? Does my custom route look correct? Has anyone seen this type of behavior before?
Thanks in advance
Chris
Upvotes: 0
Views: 258
Reputation: 7359
are you missing an underscore in your match route? 'skills#topusers'. looks like you have defined your controller method at top_users.
Upvotes: 1