Forum: Ruby on Rails Using a helper within another helper?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Coey M. (Guest)
on 2006-05-03 22:44
I am trying to push some view logic into a helper.  The thought is that
this is a step towards having the business logic in the helper rather
than the view.  However, I'm essentially wrapping the checks around an
eventual call to date_select().  The problem I'm having is that the
application complains that it doesn't know about date_select().  I'm
sure (or hope) it's simple, but so far, I haven't issued the right

To give an example of what I'm doing:
from the view:

    <%= format_planned_start_date @plan, 'plan', 'planned_to_start_on',
'Planned Start Date' %>

and from my helper:

require 'date'

module HtmlHelper
  helper :date_helper
  include DateHelper

  def format_planned_start_date(obj, obj_name, field_name, label)
    text = "<tr><td valign=\"top\"><label
    text += "</label></td>\n"
    if obj[field_name].nil? or < obj[field_name]
      text += "<td>"
      text += date_select obj_name, field_name
      text += "</td></tr>\n"
      text += "<td><p>#{obj[field_name]}</p></td></tr>\n"

The above gives the error: undefined method `helper' for
I've also tried "require 'date_helper'" at the top and without the
"helper :date_helper" without success.

I'll still poke at this, but I'm not seeing the obvious solution.
Coey M. (Guest)
on 2006-05-03 22:53
Answering my own question, I just removed the "helper :date_helper" and
"include DateHelper" lines and it worked.  I confused myself because in
earlier version, I had mistakenly wrapped the "date_select" statement in
"<%= .. %>" tags, thinking it would be re-evaluated.  When it wasn't, I
initially assumed that DateHelper wasn't being pulled in.  When I
figured out that that wasn't the issue, I forgot to remove the added

Sorry for the noise (but maybe it will help someone else down the line).
Charlie B. (Guest)
on 2006-05-03 23:05
(Received via mailing list)
It's always appreciated when you post an answer to a problem, even if it
is your own question :)

Charlie bowman
This topic is locked and can not be replied to.