Just getting started with Rails and I am having a problem defining a route. None of the documentation I can seems to resolve the issue and I am getting an undefined local variable or method error.
I need to click on a link and take a specific action, sortit. sortit does not have a view because it sorts mystuff objects and then redirects to the index page. When I use one of the predefined actions then in fact everything works. Of course none of the predefined actions are what I want to do.
my /config/routes.rb file:
match "/mystuff/sortit'", :controller => "mystuff", :action => "sortit"
resources :mystuff
my /app/controllers/mystuff_controller.rb file
class MystuffController < ApplicationController
....
def sortit
@mystuff.sort
redirect_to_mystuff_path
end
....
end
my /app/views/mystuff/index.html.haml file:
-# This file is app/views/mystuff/index.html.haml
%h1 All My Stuff
%table#mystuff
%thead
%tr
%th= link_to raw("Type"), sortit
....
As I said, when I replace sortit with a predefined action, then that action is executed. However sortit fails with this error:
undefined local variable or method `sortit' for #<#<Class:0x9997a10>:0x997c0f8>
app/views/mystuff/index.html.haml:7:in `_app_views_mystuff_index_html_haml__61272557_87671610'
So what have I missed and how do I get sortit to execute when clicking on the generated link for Type?
Thanks!
PS: My rake routes output:
mystuff GET /mystuff (.:format) {:action=>"index", :controller=>"mystuff"}
....
mystuff_sortit /mystuff/sortit (.:format) {:controller=>"mystuff", :action=>"sortit"}
....
So rake routes shows my route with the name mystuff_sorit - but aren't actions prepended to the object name? Shouldn't it be sortit_mystuff instead?