forum init.

This commit is contained in:
fanqiang 2013-11-22 10:24:15 +08:00
parent 5de8e1c2f2
commit 16f70437d1
12 changed files with 181 additions and 0 deletions

View File

@ -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.

View File

@ -0,0 +1,4 @@
/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
*/

View File

@ -0,0 +1,83 @@
class ForumsController < ApplicationController
# GET /forums
# GET /forums.json
def index
@forums = Forum.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @forums }
end
end
# GET /forums/1
# GET /forums/1.json
def show
@forum = Forum.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @forum }
end
end
# GET /forums/new
# GET /forums/new.json
def new
@forum = Forum.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @forum }
end
end
# GET /forums/1/edit
def edit
@forum = Forum.find(params[:id])
end
# POST /forums
# POST /forums.json
def create
@forum = Forum.new(params[:forum])
respond_to do |format|
if @forum.save
format.html { redirect_to @forum, notice: 'Forum was successfully created.' }
format.json { render json: @forum, status: :created, location: @forum }
else
format.html { render action: "new" }
format.json { render json: @forum.errors, status: :unprocessable_entity }
end
end
end
# PUT /forums/1
# PUT /forums/1.json
def update
@forum = Forum.find(params[:id])
respond_to do |format|
if @forum.update_attributes(params[:forum])
format.html { redirect_to @forum, notice: 'Forum was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @forum.errors, status: :unprocessable_entity }
end
end
end
# DELETE /forums/1
# DELETE /forums/1.json
def destroy
@forum = Forum.find(params[:id])
@forum.destroy
respond_to do |format|
format.html { redirect_to forums_url }
format.json { head :no_content }
end
end
end

View File

@ -0,0 +1,2 @@
module ForumsHelper
end

3
app/models/forum.rb Normal file
View File

@ -0,0 +1,3 @@
class Forum < ActiveRecord::Base
# attr_accessible :title, :body
end

View File

@ -0,0 +1,17 @@
<%= form_for(@forum) do |f| %>
<% if @forum.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@forum.errors.count, "error") %> prohibited this forum from being saved:</h2>
<ul>
<% @forum.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -0,0 +1,6 @@
<h1>Editing forum</h1>
<%= render 'form' %>
<%= link_to 'Show', @forum %> |
<%= link_to 'Back', forums_path %>

View File

@ -0,0 +1,21 @@
<h1>Listing forums</h1>
<table>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
<% @forums.each do |forum| %>
<tr>
<td><%= link_to 'Show', forum %></td>
<td><%= link_to 'Edit', edit_forum_path(forum) %></td>
<td><%= link_to 'Destroy', forum, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Forum', new_forum_path %>

View File

@ -0,0 +1,5 @@
<h1>New forum</h1>
<%= render 'form' %>
<%= link_to 'Back', forums_path %>

View File

@ -0,0 +1,5 @@
<p id="notice"><%= notice %></p>
<%= link_to 'Edit', edit_forum_path(@forum) %> |
<%= link_to 'Back', forums_path %>

View File

@ -16,6 +16,31 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
RedmineApp::Application.routes.draw do
resources :forums do
member do
get 'settings(/:tab)', :action => 'settings', :as => 'settings'
post 'modules'
post 'archive'
post 'unarchive'
post 'close'
post 'reopen'
match 'copy', :via => [:get, :post]
end
shallow do
resources :memberships, :controller => 'members', :only => [:index, :show, :new, :create, :update, :destroy] do
collection do
get 'autocomplete'
end
end
end
resources :boards
end
resources :shares
#added by william

View File

@ -0,0 +1,8 @@
class CreateForums < ActiveRecord::Migration
def change
create_table :forums do |t|
t.timestamps
end
end
end