$ rails bbs $ cd bbs $ mysql -u root $ create database bbs_develpment;
$ruby script/generate model coment
これでいくつかのファイルが作成されます。
001_create_coments.rb
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のテーブルのカラムを追加します
でSQLのテーブルのカラムを追加します
$bbs> rake db:migrate
korede
$bbs> ruby script/controller user
korede
$bbs> ruby script/controller user
user_controller.rb
class UserController < ApplicationController
scaffold :coment
end
$bbs> ruby script/server
http://localhost:3000/user
http://localhost:3000/user
この状態ではまだModelと Controllerしか使っていませんし
見た目も掲示板ではなくアドレス帳っといった感じです。
見た目も掲示板ではなくアドレス帳っといった感じです。
$bbs> ruby script/generate scaffold coment user
上書き
上書き
before
app/views/user/list.rhtml
app/views/user/list.rhtml
<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
app/views/user/list.rhtml
<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)
このページへのアクセス数
total
-
today
-
yesterday
-
total
-
today
-
yesterday
-