SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Evangelist winterheat's Avatar
    Join Date
    Aug 2007
    Posts
    508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    In Ruby on Rails, how to ensure files include the same javascript file only once?

    In Ruby on Rails, if a partial (such as _msgbox.html.erb) need to use Javascript by

    Code:
    javascript_include_tag :defaults
    but then, the page layout or other view may also have that same line, so the same javascript files will be included multiple time?

    Is there a way to tell Rails just to include it at most once? kind of like the PHP ways of require_once or include_once

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Location
    Cleveland, OH
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's already included in the layout, you won't need it in the partial. If you are wanting to customize the js loaded for each page, so you can better control load times, I would look into the content_for method.

    A great explanation can be found here http://guides.rubyonrails.org/layout...rendering.html in sections 3.2 and 3.3

    Hope this helps.

  3. #3
    SitePoint Member
    Join Date
    Jun 2010
    Location
    San Jose California
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to include the javascript in the layout so that you do not need to include it in other files.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •