Better to keep things separate, Ken.
For your problem, I'd try including a javascript based on the
controller or action name.
## helpers/application.rb
def include_javascript_extras
javascripts_path = "#{RAILS_ROOT}/public/javascripts/"
javascripts = [ "#{controller.controller_name}", "#
{controller.controller_name}_#{controller.action_name}" ]
javascripts.collect! do |name|
if FileTest.exist?("#{javascripts_path}/#{name}.css")
javascript_include_tag(name)
end
end
javascripts.compact.join("\n")
end
## app/views/layouts/application.rhtml
<head>
<%= javascript_include_tag :defaults %>
<%= include_javascript_extras %>
</head>
<body>
<%= yield %>
</body>
</html
-- Patrick
On Feb 23, 2007, at 3:00 PM, Kenneth Lee wrote:
On a somewhat-related note, how are you guys handling supplemental
Javascript libraries that you may want to include on a view, but
not across the application (or even layout for the controller)?
It's a similar concern as the title. As the view often best knows
what the title of the page should be, it also knows whether there
are other Javascript libraries that should be included.
I've put this in my layout:
<% (@extra_js_libs || []).each do |lib| -%>
<%= javascript_include_tag lib %>
<% end -%>
with this showing up in my view:
<% @extra_js_libs = ["comments", "voting"] %>
I'm not happy with it, but it works. I'm wondering if it'd be
nicer to combine this in a way with our "t" helper, something like
this within the views:
<% for_layout :title, "abcdef"
for_layout :javascript, ["script1", "script2"] %>
Just thinking out-loud here.. curious to see what others are doing.
On 2/23/07, Patrick Crowley <[EMAIL PROTECTED]> wrote: Jibba jabba!
-- Patrick
On Feb 23, 2007, at 2:34 pm, Nathan Colgate Clark wrote:
> Slick! Murdock approves!
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby