Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Generated scaffold forum

  • Loading branch information...
commit ace206b7bc7b605e1a71f5eaefe9d8829c5ef705 1 parent 3a03800
@digoonrails authored
View
3  app/assets/javascripts/forums.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/forums.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the forums controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
83 app/controllers/forums_controller.rb
@@ -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 :ok }
+ 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 :ok }
+ end
+ end
+end
View
2  app/helpers/forums_helper.rb
@@ -0,0 +1,2 @@
+module ForumsHelper
+end
View
2  app/models/forum.rb
@@ -0,0 +1,2 @@
+class Forum < ActiveRecord::Base
+end
View
25 app/views/forums/_form.html.haml
@@ -0,0 +1,25 @@
+= form_for @forum do |f|
+ -if @forum.errors.any?
+ #error_explanation
+ %h2= "#{pluralize(@forum.errors.count, "error")} prohibited this forum from being saved:"
+ %ul
+ - @forum.errors.full_messages.each do |msg|
+ %li= msg
+
+ .field
+ = f.label :name
+ = f.text_field :name
+ .field
+ = f.label :description
+ = f.text_field :description
+ .field
+ = f.label :position
+ = f.number_field :position
+ .field
+ = f.label :topics_count
+ = f.number_field :topics_count
+ .field
+ = f.label :posts_count
+ = f.number_field :posts_count
+ .actions
+ = f.submit 'Save'
View
7 app/views/forums/edit.html.haml
@@ -0,0 +1,7 @@
+%h1 Editing forum
+
+= render 'form'
+
+= link_to 'Show', @forum
+\|
+= link_to 'Back', forums_path
View
27 app/views/forums/index.html.haml
@@ -0,0 +1,27 @@
+%h1 Listing forums
+
+%table
+ %tr
+ %th Name
+ %th Description
+ %th Position
+ %th Topics count
+ %th Posts count
+ %th
+ %th
+ %th
+
+ - @forums.each do |forum|
+ %tr
+ %td= forum.name
+ %td= forum.description
+ %td= forum.position
+ %td= forum.topics_count
+ %td= forum.posts_count
+ %td= link_to 'Show', forum
+ %td= link_to 'Edit', edit_forum_path(forum)
+ %td= link_to 'Destroy', forum, :confirm => 'Are you sure?', :method => :delete
+
+%br
+
+= link_to 'New Forum', new_forum_path
View
5 app/views/forums/new.html.haml
@@ -0,0 +1,5 @@
+%h1 New forum
+
+= render 'form'
+
+= link_to 'Back', forums_path
View
21 app/views/forums/show.html.haml
@@ -0,0 +1,21 @@
+%p#notice= notice
+
+%p
+ %b Name:
+ = @forum.name
+%p
+ %b Description:
+ = @forum.description
+%p
+ %b Position:
+ = @forum.position
+%p
+ %b Topics count:
+ = @forum.topics_count
+%p
+ %b Posts count:
+ = @forum.posts_count
+
+= link_to 'Edit', edit_forum_path(@forum)
+\|
+= link_to 'Back', forums_path
View
15 test/fixtures/forums.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ name: MyString
+ description: MyString
+ position: 1
+ topics_count: 1
+ posts_count: 1
+
+two:
+ name: MyString
+ description: MyString
+ position: 1
+ topics_count: 1
+ posts_count: 1
View
49 test/functional/forums_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ForumsControllerTest < ActionController::TestCase
+ setup do
+ @forum = forums(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:forums)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create forum" do
+ assert_difference('Forum.count') do
+ post :create, forum: @forum.attributes
+ end
+
+ assert_redirected_to forum_path(assigns(:forum))
+ end
+
+ test "should show forum" do
+ get :show, id: @forum.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @forum.to_param
+ assert_response :success
+ end
+
+ test "should update forum" do
+ put :update, id: @forum.to_param, forum: @forum.attributes
+ assert_redirected_to forum_path(assigns(:forum))
+ end
+
+ test "should destroy forum" do
+ assert_difference('Forum.count', -1) do
+ delete :destroy, id: @forum.to_param
+ end
+
+ assert_redirected_to forums_path
+ end
+end
View
7 test/unit/forum_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ForumTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/forums_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ForumsHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.