• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

[ruby]railstempatetags

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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>

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
windows7下安装gem包---bcrypt-ruby发布时间:2022-07-13
下一篇:
Ruby on rails开发从头来(windows)(六)-美化你的列表页面发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap