Hi all, I''d like to put some special javascript in the head of one page? Do I need to make a separate layout for it? Or what''s the rails preferred way to accomplish this? Thank you for your help, Brent __________________________________ Yahoo! Mail - PC Magazine Editors'' Choice 2005 http://mail.yahoo.com
On 10/10/05, Brent Beardsley <brentbeardsley-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I''d like to put some special javascript in the head of > one page? Do I need to make a separate layout for it? > Or what''s the rails preferred way to accomplish this? > > Thank you for your help, > > BrentHi Brent, Link_to_unless and link_to_if were just mentionned on the list :) this and the controller variable (with a controller_name and an action_name attribute) should allow you to do what you want http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html Jean
On 10.10.2005, at 3.32, Brent Beardsley wrote:> Hi all, > > I''d like to put some special javascript in the head of > one page? Do I need to make a separate layout for it? > Or what''s the rails preferred way to accomplish this?Use the content_for [1] method for this: In the layout file: <script type="text/javascript"> <%= @content_for_script %> </script> And in a view that needs some javascript: <% content_for("script") do %> alert(''hello world'') <% end %> If you don''t want the script tags in the layout (e.g. if it''s rare that a page needs to put some scripts to the head section), you can move them inside the content_for block, too. Then you are going to repeat them in every view that needs the scripts, though. The content_for system is totally generic, you can replace the script here with any keyword, like content_for("style"). //jarkko [1] http://rails.rubyonrails.com/classes/ActionView/Helpers/ CaptureHelper.html> > Thank you for your help, > > Brent > > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors'' Choice 2005 > http://mail.yahoo.com > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
is there a way to include .rhtml file in another .rhtml file? On 10/10/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > On 10.10.2005, at 3.32, Brent Beardsley wrote: > > > Hi all, > > > > I''d like to put some special javascript in the head of > > one page? Do I need to make a separate layout for it? > > Or what''s the rails preferred way to accomplish this? > > Use the content_for [1] method for this: > > In the layout file: > > <script type="text/javascript"> > <%= @content_for_script %> > </script> > > And in a view that needs some javascript: > > <% content_for("script") do %> > alert(''hello world'') > <% end %> > > If you don''t want the script tags in the layout (e.g. if it''s rare > that a page needs to put some scripts to the head section), you can > move them inside the content_for block, too. Then you are going to > repeat them in every view that needs the scripts, though. > > The content_for system is totally generic, you can replace the script > here with any keyword, like content_for("style"). > > //jarkko > > > [1] http://rails.rubyonrails.com/classes/ActionView/Helpers/ > CaptureHelper.html > > > > > Thank you for your help, > > > > Brent > > > > > > > > > > __________________________________ > > Yahoo! Mail - PC Magazine Editors'' Choice 2005 > > http://mail.yahoo.com > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > 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 10.10.2005, at 14.44, Onur Turgay wrote:> is there a way to include .rhtml file in another .rhtml file?Oh yes, using partials [1]: "In a template for Advertiser#account: <%= render :partial => "account" %> This would render "advertiser/_account.rhtml" and pass the instance variable @account in as a local variable account to the template for display." //jarkko [1] http://rails.rubyonrails.com/classes/ActionView/Partials.html -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Jarkko, This is exactly what I was looking for. Thanks, Brent --- Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > On 10.10.2005, at 3.32, Brent Beardsley wrote: > > > Hi all, > > > > I''d like to put some special javascript in the > head of > > one page? Do I need to make a separate layout for > it? > > Or what''s the rails preferred way to accomplish > this? > > Use the content_for [1] method for this: > > In the layout file: > > <script type="text/javascript"> > <%= @content_for_script %> > </script> > > And in a view that needs some javascript: > > <% content_for("script") do %> > alert(''hello world'') > <% end %> > > If you don''t want the script tags in the layout > (e.g. if it''s rare > that a page needs to put some scripts to the head > section), you can > move them inside the content_for block, too. Then > you are going to > repeat them in every view that needs the scripts, > though. > > The content_for system is totally generic, you can > replace the script > here with any keyword, like content_for("style"). > > //jarkko > > > [1] >http://rails.rubyonrails.com/classes/ActionView/Helpers/> > CaptureHelper.html > > > > > Thank you for your help, > > > > Brent > > > > > > > > > > __________________________________ > > Yahoo! Mail - PC Magazine Editors'' Choice 2005 > > http://mail.yahoo.com > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/