[ruby] rails tempate tags
Javascript
html.erb
<!-- 本地目录(public) -->
<%= javascript_include_tag "main" %>
<!-- 本地多级目录(public) -->
<%= javascript_include_tag "photos/columns" %>
<!-- 远程js链接 -->
<%= javascript_include_tag "http://example.com/main.js" %>
html
<script src='/javascripts/main.js' type="text/javascript"></script>
<script src='/javascripts/photos/columns.js' type="text/javascript"></script>
<script src='http://example.com/main.js' type="text/javascript"></script>
CSS
html.erb
<%= stylesheet_link_tag "main","/photos/columns" %>
<%= stylesheet_link_tag "http://example.com/main.css" %>
html
<link href="/stylesheets/main.css" media="screen" rel="stylesheet" type="text/css" /> <link href="/stylesheets/photos/columns.css" media="screen" rel="stylesheet" type="text/css" />
<link href="http://example.com/main.css" media="screen" rel="stylesheet" type="text/css" />
Image
html.erb
# public/images/header.png
<%= image_tag "header.png" %>
# height
<%= image_tag "icons/delete.gif", {:height => 45} %>
# js event
<%= image_tag "home.gif", :onmouseover => "menu/home_highlight.gif" %>
# alt
<%= image_tag "home.gif", :alt => "Home" %>
# width height
<%= image_tag "home.gif", :size => "50x20" %>
#
<%= image_tag "home.gif", :alt => "Go Home",
:id => "HomeImage",
:class => 'nav_bar' %>
Video
html.erb
# public/videos/movie.ogg <%= video_tag "movie.ogg" %> # :poster => 'image_name.png', provides an image to put in place of the video before it starts playing. # :autoplay => true, starts playing the video on page load. # :loop => true, loops the video once it gets to the end. # :controls => true, provides browser supplied controls for the user to interact with the video. # :autobuffer => true, the video will pre load the file for the user on page load. <%= video_tag ["trailer.ogg", "movie.ogg"] %>
html
<video src="/videos/movie.ogg" /> <video><source src="trailer.ogg" /><source src="movie.ogg" /></video>
Audio
html.erb
# public/audios/ <%= audio_tag "music.mp3" %> <%= audio_tag "music/first_song.mp3" %> # :autoplay => true, starts playing the audio on page load # :controls => true, provides browser supplied controls for the user to interact with the audio. # :autobuffer => true, the audio will pre load the file for the user on page load
Render
html.erb
# 模板所在目录/_menu.html.erb <%= render "menu" %> # app/views/shared/_menu.html.erb <%= render "shared/menu" %> # ./_link_area.html.erb # /layouts/_graybar.html.erb <%= render :partial => "link_area", :layout => "graybar" %>
传参
new.html.erb
<h1>New zone</h1> <%= error_messages_for :zone %> <%= render :partial => "form", :locals => { :zone => @zone } %>
edit.html.erb
<h1>Editing zone</h1> <%= error_messages_for :zone %> <%= render :partial => "form", :locals => { :zone => @zone } %>
_form.html.erb
<%= form_for(zone) do |f| %> <p> <b>Zone name</b><br /> <%= f.text_field :name %> </p> <p> <%= f.submit %> </p> <% end %>
Rendering Collections
index.html.erb
<h1>Products</h1> <%= render :partial => "product", :collection => @products %>
_product.html.erb
<p>Product Name: <%= product.name %></p>
think in coding