rails: helper methods not found

R

ritchie

hi there

I'm trying to use helpers in my controller, but they're not turning up.

NoMethodError in Switcher#index

undefined method `create_menu' for SwitcherController:Class

app/controllers/switcher_controller.rb:7:in `index'
script/server:48

I'm doing this at the top of my class

class SwitcherController < ApplicationController

helper :switcher

....

end

and the helper switcher_helper.rb exists in the helper dir

module SwitcherHelper

def create_menu(dir)
$menu = {}
menu_level(dir)
end

....

end

thanks for showing me the error of my ways ... also it is loading
switcher_helper.rb, cos if I add an exit at the top of the file it lets
me know.

ritchie
 
D

David Heinemeier Hansson

I'm trying to use helpers in my controller, but they're not turning up.
NoMethodError in Switcher#index

Helpers are _view_ helpers. The controller doesn't have access to the
methods defined in the helpers. Also, since you're following the
default naming convention, you don't need to be explicit with "helper
:switcher". That'll happen automatically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

first rails app failed 4
About RAILS 4
Pagi something :( 1
gems, helpers and rails 2
[ANN] Table Helper for Ruby on Rails 0
Newbie Rails Authentication Woes 1
rails+ajax slowness in IE 2
Layouts in Rails... 2

Members online

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top