After upgrading to 0.13 application helpers are no longer accessible from a controller. I searched and found the thread <http://thread.gmane.org/gmane.comp.lang.ruby.rails/14248> Which appeared to have the solution. I added the suggested helper :application_helper and got the following error Missing helper file helpers/application_helper_helper.rb Obviously, that was easily fixed by changing helper :application_helper to helper :application But once that runs, the controller still doesn''t have access to the helper method. I updated the directory structure and all. I am calling the helper method alone, as in: my_helper_method I''ve tried ApplicationHelper.my_helper_method and a few others, to no avail Is there a specific way I should be calling this, or am I missing something else? Here''s the method that''s calling the helper. It''s called via an ajax form submit. def show_options @option = Options.find(@params[:id]) render_text hideable_form("addOption", "Add Option", render_partial("add_option")) end Thanks in advance. I''ve been lurking here a bit, but this is only my second post, so hello to all! -- Chris Martin Web Developer Open Source & Web Standards Advocate http://www.chriscodes.com/
On Jul 12, 2005, at 1:14 PM, Chris Martin wrote:> I updated the directory structure and all. > I am calling the helper method alone, as in: > my_helper_method > > I''ve tried > ApplicationHelper.my_helper_method > and a few others, to no avail > > Is there a specific way I should be calling this, or am I missing > something else? > > Here''s the method that''s calling the helper. It''s called via an ajax > form submit. > > def show_options > @option = Options.find(@params[:id]) > render_text hideable_form("addOption", "Add Option", > render_partial("add_option")) > end > > Thanks in advance. > I''ve been lurking here a bit, but this is only my second post, so > hello to all!Can you post (or paste somewhere) the complete code for your helper? The only questions I can think to ask are the ones that are probably going to sound insultingly obvious: 1) Is your helper method in the ApplicationHelper module? 2) Is your controller descended from ApplicationController? Seeing your code might shed some more light on the issue. - Jamis
On 7/12/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote:> On Jul 12, 2005, at 1:14 PM, Chris Martin wrote: > > > I updated the directory structure and all. > > I am calling the helper method alone, as in: > > my_helper_method > > > > I''ve tried > > ApplicationHelper.my_helper_method > > and a few others, to no avail > > > > Is there a specific way I should be calling this, or am I missing > > something else? > > > > Here''s the method that''s calling the helper. It''s called via an ajax > > form submit. > > > > def show_options > > @option = Options.find(@params[:id]) > > render_text hideable_form("addOption", "Add Option", > > render_partial("add_option")) > > end > > > > Thanks in advance. > > I''ve been lurking here a bit, but this is only my second post, so > > hello to all! > > Can you post (or paste somewhere) the complete code for your helper? > The only questions I can think to ask are the ones that are probably > going to sound insultingly obvious: > > 1) Is your helper method in the ApplicationHelper module?Yep.> 2) Is your controller descended from ApplicationController?Yep.> Seeing your code might shed some more light on the issue.Here''s the application helper hideable_form is the problem helper. alternate_rows is just a helper to alternate css classes (for table rows), and the reason for requiring "Generator" I removed some other helpers to keep the size down, but they should be irrelevent ### Begin ### # The methods added to this helper will be available to all templates in the application. require ''generator'' module ApplicationHelper def alternate_rows return Generator.new { |g| loop do %w(classOne classTwo).each { |a| g.yield a } end } end def hideable_form( hidingId, title, form) form_code = ''<p> <a href="#" onclick="new Effect.Fade(this);new Effect.Appear(\''''+hidingId+''\'');" class="smallText" id="''+hidingId+''_showLink">''+title+''</a> </p><div id="''+hidingId+''" class="simpleHidingBlock" style="display:none;">'' + ''<h5 style="margin-top:5px;">''+title+''</h5>'' + form + ''<a href="#" onclick="new Effect.Fade(\''''+hidingId+''\'');new Effect.Appear(\''''+hidingId+''_showLink\'')" class="smallText">Close</a> </div>'' return form_code end end ### End ### -- Chris Martin Web Developer Open Source & Web Standards Advocate http://www.chriscodes.com/
On Jul 12, 2005, at 1:52 PM, Chris Martin wrote:> On 7/12/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote: > >> On Jul 12, 2005, at 1:14 PM, Chris Martin wrote: >> >> >>> I updated the directory structure and all. >>> I am calling the helper method alone, as in: >>> my_helper_method >>> >>> I''ve tried >>> ApplicationHelper.my_helper_method >>> and a few others, to no avail >>> >>> Is there a specific way I should be calling this, or am I missing >>> something else? >>> >>> Here''s the method that''s calling the helper. It''s called via an ajax >>> form submit. >>> >>> def show_options >>> @option = Options.find(@params[:id]) >>> render_text hideable_form("addOption", "Add Option", >>> render_partial("add_option")) >>> end >>> >>> Thanks in advance. >>> I''ve been lurking here a bit, but this is only my second post, so >>> hello to all! >>> >> >> Can you post (or paste somewhere) the complete code for your helper? >> The only questions I can think to ask are the ones that are probably >> going to sound insultingly obvious: >> >> 1) Is your helper method in the ApplicationHelper module? >> > Yep. > > >> 2) Is your controller descended from ApplicationController? >> > Yep. > > >> Seeing your code might shed some more light on the issue. >> > Here''s the application helper > > hideable_form is the problem helper. > alternate_rows is just a helper to alternate css classes (for table > rows), and the reason for requiring "Generator" > I removed some other helpers to keep the size down, but they should be > irreleventBing! And the light goes on for Jamis. Sorry about that. I thought you were trying to access the helper method from within the view, but you''re trying to call it from the controller, right? You can''t do that, directly, There are a few ways to get around this, though. The first: class MyController < ApplicationController include ApplicationHelper ... end That just plops all the methods of the ApplicationHelper right into your controller, ready for your actions to call. The other way: def show_options @option = Options.find(@params[:id]) render :inline => "<%= hideable_form("addOption", "Add Option", render_partial("add_option")) %>" end That just creates a little mini-template and renders it directly, but via the view (which has access to the helpers). This approach reduces the namespace pollution of the first one. Hope that helps, Jamis
On 7/12/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote:> On Jul 12, 2005, at 1:52 PM, Chris Martin wrote: > > > On 7/12/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote: > > > >> On Jul 12, 2005, at 1:14 PM, Chris Martin wrote: > >> > >> > >>> I updated the directory structure and all. > >>> I am calling the helper method alone, as in: > >>> my_helper_method > >>> > >>> I''ve tried > >>> ApplicationHelper.my_helper_method > >>> and a few others, to no avail > >>> > >>> Is there a specific way I should be calling this, or am I missing > >>> something else? > >>> > >>> Here''s the method that''s calling the helper. It''s called via an ajax > >>> form submit. > >>> > >>> def show_options > >>> @option = Options.find(@params[:id]) > >>> render_text hideable_form("addOption", "Add Option", > >>> render_partial("add_option")) > >>> end > >>> > >>> Thanks in advance. > >>> I''ve been lurking here a bit, but this is only my second post, so > >>> hello to all! > >>> > >> > >> Can you post (or paste somewhere) the complete code for your helper? > >> The only questions I can think to ask are the ones that are probably > >> going to sound insultingly obvious: > >> > >> 1) Is your helper method in the ApplicationHelper module? > >> > > Yep. > > > > > >> 2) Is your controller descended from ApplicationController? > >> > > Yep. > > > > > >> Seeing your code might shed some more light on the issue. > >> > > Here''s the application helper > > > > hideable_form is the problem helper. > > alternate_rows is just a helper to alternate css classes (for table > > rows), and the reason for requiring "Generator" > > I removed some other helpers to keep the size down, but they should be > > irrelevent > > Bing! And the light goes on for Jamis. Sorry about that. I thought > you were trying to access the helper method from within the view, but > you''re trying to call it from the controller, right? > > You can''t do that, directly, There are a few ways to get around this, > though. > > The first: > > class MyController < ApplicationController > include ApplicationHelper > ... > end > > That just plops all the methods of the ApplicationHelper right into > your controller, ready for your actions to call. The other way: > > def show_options > @option = Options.find(@params[:id]) > render :inline => "<%= hideable_form("addOption", "Add Option", > render_partial("add_option")) %>" > end > > That just creates a little mini-template and renders it directly, but > via the view (which has access to the helpers). This approach reduces > the namespace pollution of the first one. > > Hope that helps, > > Jamis > >Thanks! Seems sometimes subject lines aren''t simple enough ;) Looks like that will work, or at least get me past one error and on to another. Although no 500''s are thrown, the second method doesn''t render the partial template that''s passed into my helper. I had to change the syntax a bit. Maybe that''s the case? render :inline => "<%= hideable_form(''addOption'', ''Add Option'', render_partial(''add_option'')) %>" All I changed was the single quotes in the helper method call. The first throws a double render error. I understand the error, but it seems illogical here, because I''m just passing the result of render_partial into the helper, which just so happens to be called from render_text. Shouldn''t that be allowed? Seeing as there''s been some changes to render in 0.13, I''m gonna go over the render page in the docs again. Thanks again for your time and thoughts! -- Chris Martin Web Developer Open Source & Web Standards Advocate http://www.chriscodes.com/
On 7/12/05, Chris Martin <chriscodes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > The first throws a double render error. I understand the error, but it > seems illogical here, because I''m just passing the result of > render_partial into the helper, which just so happens to be called > from render_text. > Shouldn''t that be allowed?In case it might help some one else, render_component_as_string() worked. render_component_as_string( hideable_form(''addOption'', ''Add Option'', render_partial(''add_option'')) ) -- Chris Martin Web Developer Open Source & Web Standards Advocate http://www.chriscodes.com/