Ruby on Rails Asset Tag Helpers

翻譯並摘自http://guides.rubyonrails.org/layouts_and_rendering.htmljavascript

Asset tag helpers provide methods for generating HTML that link views to feeds, JavaScript, stylesheets, images, videos and audios. html

  1. auto_discovery_link_tag
  2. javascript_include_tag
  3. stylesheet_link_tag
  4. image_tag
  5. video_tag
  6. audio_tag 

javascript_include_tag 

早期的Rails,js目錄在public/javascripts目錄,使用了Asset Pipeline以後,js目錄在/assets/javascripts。java

 <%= javascript_include_tag "main" %>

rails輸出爲ios

<script src='/public/javascripts/main.js'></script>

注:若是是Asset Pipeline,rails輸出則爲<script src='/assets/javascripts/main.js'></script>ruby

<%= javascript_include_tag "main", "columns" %>

輸出爲ide

<script src='/public/javascripts/main.js'></script>
<script src='/public/javascripts/columns.js'></script>

stylesheet_link_tag與javascript_include_tag 相似,再也不贅述ui

相關文章
相關標籤/搜索