Adding a simple action to controller


I am trying to get the hang of rails. It has been going well, except
now I am trying to add an action to a controller and am having trouble.
I have a LinkCategory class which extends activerecord. In its
controller, I added a method ‘display’ which lists the categories with
its links. I then created a new view, display.rhtml.

Wehn I navigate to localhost:3000/link_categories/display page, my view
is rendered, but the display method in the controller does not seem to
be exectued. At first, I was running a find across link categories in
the controller and then attempting to use it in the view:

def display
@link_categories = LinkCategory.find(:all)

When the view is rendered, I am told that @link_categories is a nil
object. I know that query returns a number of rows. I tried shorting
the method to ensure that it was being executed by adding a:
redirect_to :action => ‘list’
at the very beginning of the method, but the display view is still
rendered. I was wondering if I had misconfigured something, or
neglected to add a mapping, that was keeping the code in the controller
from being executed. I still have the default routes configured. Any
help would be appreciated.


Calling an action ‘display’ is one of those unwritten things that
doesn’t work. Rename it and you should be fine, perhaps ‘show’.

  • Gabriel

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs