「Ruby on Rails で作る簡易掲示板」の編集履歴(バックアップ)一覧はこちら
「Ruby on Rails で作る簡易掲示板」(2009/07/13 (月) 22:10:55) の最新版変更点
追加された行は緑色になります。
削除された行は赤色になります。
//*Ruby on Rails で作る簡易掲示板
$ rails bbs
$ cd bbs
$ mysql -u root
$ create database bbs_develpment;
$ruby script/generate model coment
これでいくつかのファイルが作成されます。
001_create_coments.rb
#codehighlight(ruby){{
class CreateComents < ActiveRecord::Migration
def self.up
create_table :coments do |t|
t.column :name, :string 以下追加
t.column :coment, :text
t.column :created_at, :timestamp ココまで
end
end
def self.down
drop_table :coments
end
end}}
t.column :(カラム名):(カラムの型)
でSQLのテーブルのカラムを追加します
$bbs> rake db:migrate
korede
$bbs> ruby script/controller user
user_controller.rb
#codehighlight(ruby){{
class UserController < ApplicationController
scaffold :coment
end}}
$bbs> ruby script/server
http://localhost:3000/user
この状態ではまだModelと Controllerしか使っていませんし
見た目も掲示板ではなくアドレス帳っといった感じです。
$bbs> ruby script/generate scaffold coment user
上書き
before
app/views/user/list.rhtml
#codehighlight(ruby){{
<h1>Listing coments</h1>
<table>
<tr>
<% for column in Coment.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<% for coment in @coments %>
<tr>
<% for column in Coment.content_columns %>
<td><%=h coment.send(column.name) %></td>
<% end %>
<td><%= link_to 'Show', :action => 'show', :id => coment %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => coment %></td>
<td><%= link_to 'Destroy', { :action => 'destroy', :id => coment }, :confirm => 'Are you sure?', :method => :post %></td>
</tr>
<% end %>
</table>
<%= link_to 'Previous page', { :page => @coment_pages.current.previous } if @coment_pages.current.previous %>
<%= link_to 'Next page', { :page => @coment_pages.current.next } if @coment_pages.current.next %>
<br />
<%= link_to 'New coment', :action => 'new' %>}}
after
app/views/user/list.rhtml
#codehighlight(ruby){{
<h1>Listing coments</h1>
<hr>
<% for coment in @coments %>
<h><%=h coment.id %>
Name:<%=h coment.name %>
time:<%=h coment.created_at %></h>
<%= link_to 'Destroy', { :action => 'destroy', :id => coment }, :confirm => 'Are you sure?', :method => :post %>
<br>
<h><%=h coment.coment %></h><br>
<hr>
<% end %>
<%= link_to 'Previous page', { :page => @coment_pages.current.previous } if @coment_pages.current.previous %>
<%= link_to 'Next page', { :page => @coment_pages.current.next } if @coment_pages.current.next %>
<br />
<%= link_to 'new_coment', :action => 'new' %>}}
この記事はまだ書きかけです
#comment()
このページへのアクセス数
total
&counter()
today
&counter(today)
yesterday
&counter(yesterday)
このページのタグ一覧
&tags_list()
//*Ruby on Rails で作る簡易掲示板
$ rails bbs
$ cd bbs
$ mysql -u root
$ create database bbs_develpment;
$ruby script/generate model coment
これでいくつかのファイルが作成されます。
001_create_coments.rb
#codehighlight(ruby){{
class CreateComents < ActiveRecord::Migration
def self.up
create_table :coments do |t|
t.column :name, :string 以下追加
t.column :coment, :text
t.column :created_at, :timestamp ココまで
end
end
def self.down
drop_table :coments
end
end}}
t.column :(カラム名):(カラムの型)
でSQLのテーブルのカラムを追加します
$bbs> rake db:migrate
korede
$bbs> ruby script/controller user
user_controller.rb
#codehighlight(ruby){{
class UserController < ApplicationController
scaffold :coment
end}}
$bbs> ruby script/server
http://localhost:3000/user
この状態ではまだModelと Controllerしか使っていませんし
見た目も掲示板ではなくアドレス帳っといった感じです。
$bbs> ruby script/generate scaffold coment user
上書き
before
app/views/user/list.rhtml
#codehighlight(ruby){{
<h1>Listing coments</h1>
<table>
<tr>
<% for column in Coment.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<% for coment in @coments %>
<tr>
<% for column in Coment.content_columns %>
<td><%=h coment.send(column.name) %></td>
<% end %>
<td><%= link_to 'Show', :action => 'show', :id => coment %></td>
<td><%= link_to 'Edit', :action => 'edit', :id => coment %></td>
<td><%= link_to 'Destroy', { :action => 'destroy', :id => coment }, :confirm => 'Are you sure?', :method => :post %></td>
</tr>
<% end %>
</table>
<%= link_to 'Previous page', { :page => @coment_pages.current.previous } if @coment_pages.current.previous %>
<%= link_to 'Next page', { :page => @coment_pages.current.next } if @coment_pages.current.next %>
<br />
<%= link_to 'New coment', :action => 'new' %>}}
after
app/views/user/list.rhtml
#codehighlight(ruby){{
<h1>Listing coments</h1>
<hr>
<% for coment in @coments %>
<h><%=h coment.id %>
Name:<%=h coment.name %>
time:<%=h coment.created_at %></h>
<%= link_to 'Destroy', { :action => 'destroy', :id => coment }, :confirm => 'Are you sure?', :method => :post %>
<br>
<h><%=h coment.coment %></h><br>
<hr>
<% end %>
<%= link_to 'Previous page', { :page => @coment_pages.current.previous } if @coment_pages.current.previous %>
<%= link_to 'Next page', { :page => @coment_pages.current.next } if @coment_pages.current.next %>
<br />
<%= link_to 'new_coment', :action => 'new' %>}}
この記事はまだ書きかけです
- ああ -- ああ (2009-07-13 22:10:55)
#comment()
このページへのアクセス数
total
&counter()
today
&counter(today)
yesterday
&counter(yesterday)
このページのタグ一覧
&tags_list()
表示オプション
横に並べて表示:
変化行の前後のみ表示: