Skip to content
This repository has been archived by the owner on Apr 24, 2018. It is now read-only.

Commit

Permalink
added post controller and model
Browse files Browse the repository at this point in the history
  • Loading branch information
chrjoh committed Nov 2, 2011
1 parent 9bb2554 commit 3b03e24
Show file tree
Hide file tree
Showing 27 changed files with 252 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -21,6 +21,7 @@ gem "mongoid"
gem 'mongoid_taggable'
gem 'mongoid-generator'
gem "haml"
gem 'kaminari'
gem "haml-rails", :group => :development

# To use ActiveModel has_secure_password
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -90,6 +90,8 @@ GEM
thor (~> 0.14)
json (1.6.1)
json_pure (1.6.1)
kaminari (0.12.4)
rails (>= 3.0.0)
launchy (2.0.5)
addressable (~> 2.2.6)
mail (2.3.0)
Expand Down Expand Up @@ -205,6 +207,7 @@ DEPENDENCIES
haml
haml-rails
jquery-rails
kaminari
launchy
mongoid
mongoid-generator
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/posts.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/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/posts.css.scss
@@ -0,0 +1,3 @@
// Place all the styles related to the posts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
38 changes: 38 additions & 0 deletions app/controllers/posts_controller.rb
@@ -0,0 +1,38 @@
class PostsController < ApplicationController

def index
@posts = Post.all
@posts = @posts.page params[:page] unless @posts.count == 0
respond_to do |format|
format.html
format.any(:json) { render request.format.to_sym => @posts }
end
end

def show
@post = Post.find(params[:id])
respond_to do |format|
format.html
format.any(:json) { render request.format.to_sym => @post }
end
end

def create
@post = Post.new(params[:post])
@post.save
redirect_to post_path(@post)
end

def update
end

def destroy
end

def new
@post = Post.new
end

def edit
end
end
2 changes: 2 additions & 0 deletions app/helpers/posts_helper.rb
@@ -0,0 +1,2 @@
module PostsHelper
end
6 changes: 6 additions & 0 deletions app/models/post.rb
@@ -0,0 +1,6 @@
class Post
include Mongoid::Document
field :title, :type => String
field :body, :type => String
field :published, :type => Boolean
end
24 changes: 24 additions & 0 deletions app/views/posts/_form.html.haml
@@ -0,0 +1,24 @@
.first.grid1 &nbsp;
= form_for @post, :html => {:class => 'grid10 main_form'} do |f|
.first.grid10.box
.first.grid10.subhead
.first.grid2.label
%h3 Post
.first.grid2.label
= f.label :title, "Title"
.grid8.field
= f.text_field :title

.first.grid2.label
= f.label :body, "Body"
.grid8.field
= f.text_area :body

.first.grid2.label
= f.label :published, "Published"
.grid8.field
= f.check_box :published

.first.grid10.submit
= f.submit :class => 'button save'

2 changes: 2 additions & 0 deletions app/views/posts/create.html.haml
@@ -0,0 +1,2 @@
%h1 Posts#create
%p Find me in app/views/posts/create.html.haml
2 changes: 2 additions & 0 deletions app/views/posts/destroy.html.haml
@@ -0,0 +1,2 @@
%h1 Posts#destroy
%p Find me in app/views/posts/destroy.html.haml
Empty file added app/views/posts/edit.html.haml
Empty file.
20 changes: 20 additions & 0 deletions app/views/posts/index.html.haml
@@ -0,0 +1,20 @@
.grid1.first &nbsp;

.grid10.box
.first.grid10.subhead
.first.grid2.label
%h3 Posts
- for post in @posts
.first.grid10.article_row
.first.grid2
= post.title
.grid6
.first.grid6
= post.body

.first.grid10
-#= paginate @posts
.grid1.first &nbsp;
.grid10
= link_to('new post', new_post_url, :class => "button add")
1 change: 1 addition & 0 deletions app/views/posts/new.html.haml
@@ -0,0 +1 @@
= render :partial => 'form'
9 changes: 9 additions & 0 deletions app/views/posts/show.html.haml
@@ -0,0 +1,9 @@
.first.grid1 &nbsp;
.grid10.box
.first.grid10.subhead
.first.grid2.label
%h3
= @post.title
.first.grid10.article_attribute
= simple_format(@post.body)
.first.grid10.article_attribute
2 changes: 2 additions & 0 deletions app/views/posts/update.html.haml
@@ -0,0 +1,2 @@
%h1 Posts#update
%p Find me in app/views/posts/update.html.haml
8 changes: 8 additions & 0 deletions config/initializers/kaminari_config.rb
@@ -0,0 +1,8 @@
Kaminari.configure do |config|
# config.default_per_page = 25
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.param_name = :page
end
5 changes: 5 additions & 0 deletions config/routes.rb
@@ -1,4 +1,9 @@
Nssba::Application.routes.draw do

resources :posts

root :to => 'posts#index'

# The priority is based upon order of creation:
# first created -> highest priority.

Expand Down
54 changes: 54 additions & 0 deletions spec/controllers/posts_controller_spec.rb
@@ -0,0 +1,54 @@
require 'spec_helper'

describe PostsController do

describe "GET 'index'" do
it "returns http success" do
get 'index'
response.should be_success
end
end

describe "GET 'show'" do
it "returns http success" do
get 'show'
response.should be_success
end
end

describe "GET 'create'" do
it "returns http success" do
get 'create'
response.should be_success
end
end

describe "GET 'update'" do
it "returns http success" do
get 'update'
response.should be_success
end
end

describe "GET 'destroy'" do
it "returns http success" do
get 'destroy'
response.should be_success
end
end

describe "GET 'edit'" do
it "returns http success" do
get 'edit'
response.should be_success
end
end

describe "GET 'new'" do
it "returns http success" do
get 'new'
response.should be_success
end
end

end
9 changes: 9 additions & 0 deletions spec/factories/posts.rb
@@ -0,0 +1,9 @@
# Read about factories at http://github.com/thoughtbot/factory_girl

FactoryGirl.define do
factory :post do
title "MyString"
body "MyText"
published false
end
end
15 changes: 15 additions & 0 deletions spec/helpers/post_helper_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the PostHelper. For example:
#
# describe PostHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe PostHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
15 changes: 15 additions & 0 deletions spec/helpers/posts_helper_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the PostsHelper. For example:
#
# describe PostsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe PostsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/post_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Post do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/views/posts/create.html.haml_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe "posts/create.html.haml" do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/views/posts/destroy.html.haml_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe "posts/destroy.html.haml" do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/views/posts/index.html.haml_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe "posts/index.html.haml" do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/views/posts/show.html.haml_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe "posts/show.html.haml" do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/views/posts/update.html.haml_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe "posts/update.html.haml" do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 3b03e24

Please sign in to comment.