Hey How do I access methods that I have defined in helpers? __________________________________________ Helper id_browser_helper.rb: module IdBrowserHelper def table_identities(message) render_text message end end ___________________________________________ Controller id_browser_controller.rb: class IdBrowserController < ApplicationController def view_genre() table_identities('identities_box') end end ____________________________________________ This is the error message I get: NoMethodError in Id_browser#view_genre undefined method `table_identities' for #<IdBrowserController:0x385add0> What should I do? i have tried to require the helper file in the controller, but that didn't help.
on 2006-03-05 12:14
on 2006-03-05 13:30
Am Sonntag, den 05.03.2006, 12:14 +0100 schrieb last resort: > ___________________________________________ > NoMethodError in Id_browser#view_genre > undefined method `table_identities' for #<IdBrowserController:0x385add0> > > What should I do? i have tried to require the helper file in the > controller, but that didn't help. Helper methods in helper files hold code outsourced from your view, not your controller, to make code simpler or reusable. If you want to abstract code in your controllers, you have two choices: 1. Put your common methods to ApplicationController (app/controllers/application.rb), so you can use them in every controller in your application. Don't forget to make them private, so they could not be called as actions. 2. Organize it in a module and include it in the controller where you need the methods. Example: # lib/login.rb module Login def current_user # some code to find current user end end # app/controllers/comments_controller.rb class CommentsController < ApplicationController include Login def edit user = current_user end end -- Norman Timmler http://blog.inlet-media.de