Given that Rails has built in ways to do almost everything else :) , is there a way to keep view specific javascripts inside the head tag of a layout without having to include that javascript on every page? -- Marlon -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060404/65e9bb6d/attachment.html
make your include tag dynamic. I can''t remember the exact syntax but
you''ll get the picture.
<%= include_javacripts, ****** #{@my_javascript} %>
in your view do something like this:
<% @my_javascript = ''view_specifiic_javascript.js'' %>
Charlie Bowman
recentrambles.com
On Tue, 2006-04-04 at 09:05 -0600, Marlon Moyer wrote:
> Given that Rails has built in ways to do almost everything else :) ,
> is there a way to keep view specific javascripts inside the head tag
> of a layout without having to include that javascript on every page?
>
>
>
> --
> Marlon
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060404/c07fbe21/attachment.html
In your <head>, put:
<script type="text/javascript"><%=
@content_for_page_scripts %></
script>
Then in your view:
<% content_for("page_scripts") do -%>
function item_added() {
var item = $(''items'').lastChild;
new Effect.Highlight(item, { startcolor:''rgb(255,153,255)'',
endcolor:''rgb(200,200,200)'' });
Element.hide(''busy'');
$(''form-submit-button'').disabled = false;
$(''item-new-code'').value = '''';
$(''item-new-description'').value = '''';
Field.focus(''item-new-code'');
}
function item_loading() {
$(''form-submit-button'').disabled = true;
Element.show(''busy'');
}
<% end -%>
Then the stuff will be in the header on the delivered page, but close
to where you need in in your .rhtml files.
content_for() works for other stuff, too!
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
+1 513-295-4739
On Apr 4, 2006, at 12:06 PM, Charlie Bowman wrote:
> make your include tag dynamic. I can''t remember the exact syntax
> but you''ll get the picture.
>
> <%= include_javacripts, ****** #{@my_javascript} %>
>
> in your view do something like this:
> <% @my_javascript = ''view_specifiic_javascript.js''
%>
>
>
> Charlie Bowman
> recentrambles.com
>
> On Tue, 2006-04-04 at 09:05 -0600, Marlon Moyer wrote:
>> Given that Rails has built in ways to do almost everything
>> else :) , is there a way to keep view specific javascripts inside
>> the head tag of a layout without having to include that javascript
>> on every page?
>>
>>
>>
>> --
>> Marlon
>>
>> _______________________________________________
>> Rails mailing list
>> Rails@lists.rubyonrails.org
>> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060406/1f3359c0/attachment.html
thanks for the great tip. I had no idea about the @content_for command. On 4/6/06, Rob Biedenharn <Rob@agileconsultingllc.com> wrote:> > In your <head>, put: > <script type="text/javascript"><%= @content_for_page_scripts %></script> > > > Then in your view: > > <% content_for("page_scripts") do -%> > function item_added() { > var item = $(''items'').lastChild; > new Effect.Highlight(item, { startcolor:''rgb(255,153,255)'', > endcolor:''rgb(200,200,200)'' }); > Element.hide(''busy''); > $(''form-submit-button'').disabled = false; > $(''item-new-code'').value = ''''; > $(''item-new-description'').value = ''''; > Field.focus(''item-new-code''); > } > > function item_loading() { > $(''form-submit-button'').disabled = true; > Element.show(''busy''); > } > <% end -%> > > > Then the stuff will be in the header on the delivered page, but close to > where you need in in your .rhtml files. > content_for() works for other stuff, too! > > -Rob > > > Rob Biedenharn http://agileconsultingllc.com > Rob@AgileConsultingLLC.com > +1 513-295-4739 > > > On Apr 4, 2006, at 12:06 PM, Charlie Bowman wrote: > > make your include tag dynamic. I can''t remember the exact syntax but > you''ll get the picture. > > <%= include_javacripts, ****** #{@my_javascript} %> > > in your view do something like this: > <% @my_javascript = ''view_specifiic_javascript.js'' %> > > > Charlie Bowman > recentrambles.com > > On Tue, 2006-04-04 at 09:05 -0600, Marlon Moyer wrote: > > Given that Rails has built in ways to do almost everything else :) , is > there a way to keep view specific javascripts inside the head tag of a > layout without having to include that javascript on every page? > > > > -- > Marlon > > _______________________________________________Rails mailing listRails@lists.rubyonrails.orghttp://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Marlon -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060408/e2fe27be/attachment.html