ruby on rails學習筆記--Views(2)

1, Pagination 分頁

參考http://api.rubyonrails.com/   paginate(collection_id, options={})

Returns a paginator and a collection of Active Record model instances for the paginator‘s current page. This is designed to be used in a single action。

注意它有兩個返回值

 2,Layout

在app/views/下有個layout文件夾。如果使用scaffold生成的項目,layout下可以看到一個rhtml文件,內容類似如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  
<title>Moviecomment: <%= controller.action_name %></title>
  
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield  %>

</body>
</html>

這相當於所有其他rhtml的模板。假設你有另外一個view文件 show.rhtml,你在其中不必填寫header等羅索的東西,只要寫和你的業務相關的UI,執行的時候會套用這個模板。

3,partial

可能會看到這樣的代碼 render :partial => 'form'

這意味這在當前的UI頁面中會包含 _form.rhtml 的內容。

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章