Rails 2.0.2でブログシステム:テンプレートメモ
paginateがなくなっていっそうシンプルになった。
app/views/home/index.html.erb
<% for entry in @entries %> <div class="entry"> <div class="date"> <%= entry.created_on.year %>年<%= entry.created_on.month %>月<%= entry.created_on.day %>日 </div> <h2><%=h entry.title %></h2> <div><%=h entry.body %></div> <%=link_to 'permalink', :controller => 'entries', :action => 'show', :id => entry %> </div> <% end %>
showへのlink_to上記のように書くしかないのかな。同じコントローラないだともっとシンプルなのに。
app/views/layouts/application.html.erb
<!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>Pipin: <%= controller.controller_name %></title> <%= stylesheet_link_tag 'scaffold' %> <%= stylesheet_link_tag 'base' %> </head> <body> <div class="main"> <h1>Pipin</h1> <div class="header-menus"> <%= link_to 'Home', :controller => 'home', :action => '' %> <%= link_to 'Archive', :controller => 'home', :action => 'archive' %> <%= link_to 'About', :controller => 'home', :action => 'about' %> <%= link_to '日記を書く', :controller => 'entries', :action => 'new' %> <%= link_to '管理', :controller => 'entries', :action => '' %> <%= link_to 'ログアウト', :controller => 'account', :action => 'logout' %> </div> <p style="color: green"><%= flash[:notice] %></p> <%= yield %> </div> </body> </html>
ここまでのコマンド。
rails pipin cd pipin ruby script/generate scaffold Entry title:string body:text created_on:datetime rake db:create rake db:migrate rm app/views/layouts/entries.html.erb ruby script/generate controller Home index