Hi I''m on rails version 0.14.3. The methods of the controller helper module are not available in the controller instance. They are available on the view. Verified it with a plain new project. May this be a bug or am I missing something? thanks a lot in advance Martin -- Posted via http://www.ruby-forum.com/.
On 16.11.2005, at 15.03, Martin wrote:> Hi > > I''m on rails version 0.14.3. > The methods of the controller helper module are not available in the > controller instance. They are available on the view. Verified it > with a > plain new project. > > May this be a bug or am I missing something?No, that''s like it''s supposed to be. Helpers are methods meant to make views cleaner by encapsulating common behaviour in one place. They are thus not available in controllers. You can, however, include them in your controllers, as well: include DateHelper You might consider, however, whether your code is in the right place in helpers if you need a lot of it often in controllers in contrast to views. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Wed, Nov 16, 2005 at 02:03:20PM +0100, Martin wrote:> I''m on rails version 0.14.3. > The methods of the controller helper module are not available in the > controller instance. They are available on the view. Verified it with a > plain new project. > > May this be a bug or am I missing something?I can confirm it here as well. Don''t know what''s going on, though. Ronny _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
jarkko wrote:>> May this be a bug or am I missing something? > No, that''s like it''s supposed to be. Helpers are methods meant to > make views cleaner by encapsulating common behaviour in one place. > They are thus not available in controllers. > > You can, however, include them in your controllers, as well: > > include DateHelperThat makes sense, and by using "include" it works (standard ruby stuff). But if this is true there are some serious "errors" in the Rails book.>From page 554:-------------------------------------------------------------- By default, each controller gets its own helper module. It won’t be surpris- ing to learn that Rails makes certain assumptions to help link the helpers into the controller and its views. If a controller is named BlogController, it will automatically look for a helper module called BlogHelper in the file blog_helper.rb in the app/helpers directory. -------------------------------------------------------------- and there is even an example with -------------------------------------------------------------- class ParticularController < ApplicationController helper :date_format # ... -------------------------------------------------------------- and rails is not complaining when I am using "helper" but it does not work. ? Martin -- Posted via http://www.ruby-forum.com/.
On Wed, Nov 16, 2005 at 03:42:26PM +0200, Jarkko Laine wrote:> No, that''s like it''s supposed to be. Helpers are methods meant to > make views cleaner by encapsulating common behaviour in one place. > They are thus not available in controllers. > > You can, however, include them in your controllers, as well: > > include DateHelperHmm, the API docs at http://api.rubyonrails.com/classes/ActionController/Helpers/ClassMethods.html probably needs to be updated. (Or does it reflect 1.0?) ''helper :something'' doesn''t work, ''include SomeHelper'' works. Ronny _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> Hmm, the API docs at > http://api.rubyonrails.com/classes/ActionController/Helpers/Cl >assMethods.html >probably needs to be updated. (Or does it reflect 1.0?)>''helper :something'' doesn''t work, ''include SomeHelper'' works.The documentation says that the helper will be included in the "template class", so writing "helper :Something" should make the SomethingHelper module available in the view. Not in the controller... /Torben
Ronny and Martin, On 16.11.2005, at 15.55, Guest wrote:> That makes sense, and by using "include" it works (standard ruby > stuff). > But if this is true there are some serious "errors" in the Rails book. > >> From page 554: > -------------------------------------------------------------- > By default, each controller gets its own helper module. It won’t be > surpris- > ing to learn that Rails makes certain assumptions to help link the > helpers > into the controller and its views. If a controller is named > BlogController, > it will automatically look for a helper module called BlogHelper in > the > file > blog_helper.rb in the app/helpers directory. > -------------------------------------------------------------- > and there is even an example with > -------------------------------------------------------------- > class ParticularController < ApplicationController > helper :date_format > # ... > -------------------------------------------------------------- > and rails is not complaining when I am using "helper" but it does not > work.Using "helper :myhelper" will make the helper available in _the views_ of that particular controller. So helper is a perfectly working method but it''s not meant to do what you think it is. Also, like Torben mentioned, the api docs at least seem to be fine. The fact that the helpers are not available in the controller code could perhaps be stated clearly, tho. Do I hear someone volunteering for a documentation patch? //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Wed, Nov 16, 2005 at 03:16:34PM +0100, Torben Wölm wrote:> > Hmm, the API docs at > > http://api.rubyonrails.com/classes/ActionController/Helpers/Cl > >assMethods.html > >probably needs to be updated. (Or does it reflect 1.0?) > > >''helper :something'' doesn''t work, ''include SomeHelper'' works. > > The documentation says that the helper will be included in the "template class", > > so writing > > "helper :Something" > > should make the SomethingHelper module available in the view. Not in the controller...Sorry, my bad. Should''ve read more carefully. Thanks. Ronny _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails