Skip to content

Commit

Permalink
add Board
Browse files Browse the repository at this point in the history
  • Loading branch information
seouri committed Jan 29, 2012
1 parent 1f60ce7 commit 1fb4a56
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/bawi/boards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/bawi/boards.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/
85 changes: 85 additions & 0 deletions app/controllers/bawi/boards_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module Bawi
class BoardsController < ApplicationController
# GET /boards
# GET /boards.json
def index
@boards = Board.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @boards }
end
end

# GET /boards/1
# GET /boards/1.json
def show
@board = Board.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @board }
end
end

# GET /boards/new
# GET /boards/new.json
def new
@board = Board.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @board }
end
end

# GET /boards/1/edit
def edit
@board = Board.find(params[:id])
end

# POST /boards
# POST /boards.json
def create
@board = Board.new(params[:board])

respond_to do |format|
if @board.save
format.html { redirect_to @board, notice: 'Board was successfully created.' }
format.json { render json: @board, status: :created, location: @board }
else
format.html { render action: "new" }
format.json { render json: @board.errors, status: :unprocessable_entity }
end
end
end

# PUT /boards/1
# PUT /boards/1.json
def update
@board = Board.find(params[:id])

respond_to do |format|
if @board.update_attributes(params[:board])
format.html { redirect_to @board, notice: 'Board was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @board.errors, status: :unprocessable_entity }
end
end
end

# DELETE /boards/1
# DELETE /boards/1.json
def destroy
@board = Board.find(params[:id])
@board.destroy

respond_to do |format|
format.html { redirect_to boards_url }
format.json { head :no_content }
end
end
end
end
4 changes: 4 additions & 0 deletions app/helpers/bawi/boards_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Bawi
module BoardsHelper
end
end
4 changes: 4 additions & 0 deletions app/models/bawi/board.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Bawi
class Board < ActiveRecord::Base
end
end
53 changes: 53 additions & 0 deletions app/views/bawi/boards/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<%= form_for(@board) do |f| %>
<% if @board.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@board.errors.count, "error") %> prohibited this board from being saved:</h2>

<ul>
<% @board.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :group_id %><br />
<%= f.number_field :group_id %>
</div>
<div class="field">
<%= f.label :user_id %><br />
<%= f.number_field :user_id %>
</div>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :keyword %><br />
<%= f.text_field :keyword %>
</div>
<div class="field">
<%= f.label :max_article_no %><br />
<%= f.number_field :max_article_no %>
</div>
<div class="field">
<%= f.label :max_comment_no %><br />
<%= f.number_field :max_comment_no %>
</div>
<div class="field">
<%= f.label :articles_count %><br />
<%= f.number_field :articles_count %>
</div>
<div class="field">
<%= f.label :comments_count %><br />
<%= f.number_field :comments_count %>
</div>
<div class="field">
<%= f.label :bookmarks_count %><br />
<%= f.number_field :bookmarks_count %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/bawi/boards/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing board</h1>

<%= render 'form' %>
<%= link_to 'Show', @board %> |
<%= link_to 'Back', boards_path %>
39 changes: 39 additions & 0 deletions app/views/bawi/boards/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<h1>Listing boards</h1>

<table>
<tr>
<th>Group</th>
<th>User</th>
<th>Name</th>
<th>Keyword</th>
<th>Max article no</th>
<th>Max comment no</th>
<th>Articles count</th>
<th>Comments count</th>
<th>Bookmarks count</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @boards.each do |board| %>
<tr>
<td><%= board.group_id %></td>
<td><%= board.user_id %></td>
<td><%= board.name %></td>
<td><%= board.keyword %></td>
<td><%= board.max_article_no %></td>
<td><%= board.max_comment_no %></td>
<td><%= board.articles_count %></td>
<td><%= board.comments_count %></td>
<td><%= board.bookmarks_count %></td>
<td><%= link_to 'Show', board %></td>
<td><%= link_to 'Edit', edit_board_path(board) %></td>
<td><%= link_to 'Destroy', board, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Board', new_board_path %>
5 changes: 5 additions & 0 deletions app/views/bawi/boards/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New board</h1>

<%= render 'form' %>
<%= link_to 'Back', boards_path %>
50 changes: 50 additions & 0 deletions app/views/bawi/boards/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<p id="notice"><%= notice %></p>

<p>
<b>Group:</b>
<%= @board.group_id %>
</p>

<p>
<b>User:</b>
<%= @board.user_id %>
</p>

<p>
<b>Name:</b>
<%= @board.name %>
</p>

<p>
<b>Keyword:</b>
<%= @board.keyword %>
</p>

<p>
<b>Max article no:</b>
<%= @board.max_article_no %>
</p>

<p>
<b>Max comment no:</b>
<%= @board.max_comment_no %>
</p>

<p>
<b>Articles count:</b>
<%= @board.articles_count %>
</p>

<p>
<b>Comments count:</b>
<%= @board.comments_count %>
</p>

<p>
<b>Bookmarks count:</b>
<%= @board.bookmarks_count %>
</p>


<%= link_to 'Edit', edit_board_path(@board) %> |
<%= link_to 'Back', boards_path %>
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Bawi::Engine.routes.draw do
resources :groups
resources :boards

resources :groups do
resources :boards
end

root to: "groups#index"
end
21 changes: 21 additions & 0 deletions db/migrate/20120128034149_create_bawi_boards.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class CreateBawiBoards < ActiveRecord::Migration
def change
create_table :bawi_boards do |t|
t.integer :group_id, null: false, default: 0
t.integer :user_id, null: false
t.string :name, null: false
t.string :keyword, null: false
t.integer :max_article_no, null: false, default: 0
t.integer :max_comment_no, null: false, default: 0
t.integer :articles_count, null: false, default: 0
t.integer :comments_count, null: false, default: 0
t.integer :bookmarks_count, null: false, default: 0

t.timestamps
end

add_index :bawi_boards, :group_id
add_index :bawi_boards, [:user_id, :name]
add_index :bawi_boards, :keyword, unique: true
end
end
20 changes: 19 additions & 1 deletion test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,25 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120121164003) do
ActiveRecord::Schema.define(:version => 20120128034149) do

create_table "bawi_boards", :force => true do |t|
t.integer "group_id", :default => 0, :null => false
t.integer "user_id", :null => false
t.string "name", :null => false
t.string "keyword", :null => false
t.integer "max_article_no", :default => 0, :null => false
t.integer "max_comment_no", :default => 0, :null => false
t.integer "articles_count", :default => 0, :null => false
t.integer "comments_count", :default => 0, :null => false
t.integer "bookmarks_count", :default => 0, :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "bawi_boards", ["group_id"], :name => "index_bawi_boards_on_group_id"
add_index "bawi_boards", ["keyword"], :name => "index_bawi_boards_on_keyword", :unique => true
add_index "bawi_boards", ["user_id", "name"], :name => "index_bawi_boards_on_user_id_and_name"

create_table "bawi_groups", :force => true do |t|
t.integer "parent_id", :default => 0, :null => false
Expand Down
23 changes: 23 additions & 0 deletions test/fixtures/bawi/boards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
group_id: 1
user_id: 1
name: MyString
keyword: FirstBoard
max_article_no: 0
max_comment_no: 0
articles_count: 0
comments_count: 0
bookmarks_count: 0

two:
group_id: 1
user_id: 1
name: MyString
keyword: SecondBoard
max_article_no: 0
max_comment_no: 0
articles_count: 0
comments_count: 0
bookmarks_count: 0
Loading

0 comments on commit 1fb4a56

Please sign in to comment.