I have a helper that would like to use javascript to pre-load images for mouseover/mouseout events. It would be ideal if I could put the preloading code in the <script></script> header section of my layout. Is there a way to do this? I tried: content_for "script" { %Q[ ... my javascript code here ... ] } But I got this error message: undefined local variable or method `_erbout'' for #<ActionView::Base: 0x233487c> (Obviously, content_for expects to be inside of an erb template). Any ideas? Thanks, Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 5/20/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a helper that would like to use javascript to pre-load images for > mouseover/mouseout events. It would be ideal if I could put the preloading > code in the <script></script> header section of my layout. Is there a way > to do this?Have the helper just spit out your code, and then call it in your view like so: <% content_for "script", preload_mouseover_script %> -- rick http://techno-weenie.net
>> I have a helper that would like to use javascript to pre-load >> images for >> mouseover/mouseout events. It would be ideal if I could put the >> preloading >> code in the <script></script> header section of my layout. Is >> there a way >> to do this? >> > > Have the helper just spit out your code, and then call it in your > view like so: > > <% content_for "script", preload_mouseover_script %>That''s a solution I hadn''t thought of. It''s still not ideal, however, because it violates DRY... I would have to tell my helper to load each button, and then later on tell it to show each button. I''d like to be able to say, for example: <%= show_button "home", :controller => "/" %> and have the helper send the script part to the header, and the <a href><img></a> stuff to the template in place. I''m asking a lot, aren''t I? :) Duane Johnson (canadaduane)
> That''s a solution I hadn''t thought of. It''s still not ideal, > however, because it violates DRY... I would have to tell my helper to > load each button, and then later on tell it to show each button. I''d > like to be able to say, for example: > > <%= show_button "home", :controller => "/" %> > > and have the helper send the script part to the header, and the <a > href><img></a> stuff to the template in place. > > I''m asking a lot, aren''t I? :) > > Duane Johnson > (canadaduane) >Why not just append to the @script instance variable? AFAIK, content_for is really for inserting blocks of content into instance variables. I usually set page headers and breadcrumbs in my views, while rendering them in the layout.
Can you send the code exactly as it stands... helper, view, controller... off list is fine... Duane Johnson wrote:> I have a helper that would like to use javascript to pre-load images > for mouseover/mouseout events. It would be ideal if I could put the > preloading code in the <script></script> header section of my layout. > Is there a way to do this? > > I tried: > > content_for "script" { %Q[ ... my javascript code here ... ] } > > But I got this error message: > > undefined local variable or method `_erbout'' for > #<ActionView::Base:0x233487c> > > (Obviously, content_for expects to be inside of an erb template). Any > ideas? > > Thanks, > Duane Johnson > (canadaduane) > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Demetrius Nunes
2005-May-23 01:25 UTC
Re: Is there a way to use content_for in the helper?
Duane Johnson wrote:> I have a helper that would like to use javascript to pre-load images for > mouseover/mouseout events. It would be ideal if I could put the > preloading code in the <script></script> header section of my layout. > Is there a way to do this? > > I tried: > > content_for "script" { %Q[ ... my javascript code here ... ] } > > But I got this error message:Why not simply do: @content_for_script ||= "" @content_for_script << %Q[\n ... ] rgds Dema http://dema.ruby.com.br
How about looking at a completely different solution? You can use CSS to do mouse over events - see http://www.simplebits.com/notebook/2003/09/30/accessible_imagetab_rollovers.html for more details. sam On 5/23/05, Demetrius Nunes <demetrius-fDpYTK8McCzCdMRJFJuMdgh0onu2mTI+@public.gmane.org> wrote:> Duane Johnson wrote: > > I have a helper that would like to use javascript to pre-load images for > > mouseover/mouseout events. It would be ideal if I could put the > > preloading code in the <script></script> header section of my layout. > > Is there a way to do this? > > > > I tried: > > > > content_for "script" { %Q[ ... my javascript code here ... ] } > > > > But I got this error message: > > Why not simply do: > > @content_for_script ||= "" > @content_for_script << %Q[\n ... ] > > rgds > Dema > http://dema.ruby.com.br > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- sam http://www.magpiebrain.com/
Duane Johnson
2005-May-23 22:39 UTC
Re: Re: Is there a way to use content_for in the helper?
On May 23, 2005, at 6:19 AM, Sam Newman wrote:> How about looking at a completely different solution? You can use CSS > to do mouse over events - see > http://www.simplebits.com/notebook/2003/09/30/ > accessible_imagetab_rollovers.html > for more details.Fantastic! Thank-you. That''s exactly what I was looking for... but didn''t know it :) Duane Johnson (canadaduane)
No problem - there are a number of variations on the same technique, you might also want to check: http://www.alistapart.com/articles/slidingdoors/ http://www.alistapart.com/articles/slidingdoors2/ http://www.alistapart.com/articles/rollovers/ And an essential write up accesible image replacement side of things (e.g. replacing text with images, but showing the text if browsers can''t see the image): http://www.mezzoblue.com/archives/2005/03/30/image_replac/index.php On 5/23/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 23, 2005, at 6:19 AM, Sam Newman wrote: > > > How about looking at a completely different solution? You can use CSS > > to do mouse over events - see > > http://www.simplebits.com/notebook/2003/09/30/ > > accessible_imagetab_rollovers.html > > for more details. > > Fantastic! Thank-you. That''s exactly what I was looking for... but > didn''t know it :) > > Duane Johnson > (canadaduane) > >-- sam http://www.magpiebrain.com/