Rails 重玩筆記 (3)


今天終於開始重寫 OneBook 這東西了,
因為要處理 PHP 和 伺服器的事情所以又推遲了試練時間,可悲
繼續來記錄一下筆記.

之前提到的 REST 的 _url 和 _path 的分別,現時總算出了一點結果

1
2
new_gbook_path <-- /gbook/new
new_gbook_url <-- http://localhost:3000/gbook/new

再者 Layout 上面,而 OneBook 目前只用了其中的兩種

1
2
基本的有 : gobal layout,controller layout,shared layout,dynamic layout,action layout
詳細參考 : http://bbs.maxthon.cn/viewthread.php?tid=64854

再來是關於 will_paginate 的使用,這以 plugin 方式為主,我喜歡這個

1
2
3
1. 下載 will_paginate, 網站: http://github.com/mislav/will_paginate/tree/master
2. 再來是解壓放到 App 中的 vendor/plugins 中,並改資料匣名為 will_paginate
3. 因本人使用的是 NetBean,所以 Restart Web Server, 即可

至於使用上基本就是

1
2
3
4
5
class GbookController < ApplicationController
def index
@messages = Messages.paginate :page => params[:page], :order => "adddate DESC", :per_page => 2
end
end
1
2
<span class="pagination_info">Record: <%= @messages.size %></span>
<%= will_paginate @messages, :previous_label => "‹", :next_label => "›" %>