Permalink
Browse files

Adding Post scaffold

  • Loading branch information...
1 parent e949fe4 commit 4b472302673e7c1b8f7ab7fd517bce4716439a3a @williamn williamn committed Apr 20, 2012
View
@@ -5,9 +5,10 @@ gem 'sqlite3'
gem 'jquery-rails'
gem 'nifty-generators', :group => :development
-
-gem :test, :development do
- gem 'rspec-rails', '~> 2.9.0'
+gem 'rspec-rails', '~> 2.9.0', :group => [:test, :development]
+group :test do
+ gem 'shoulda-matchers', '~> 1.1.0'
+ gem 'factory_girl_rails', '~> 3.0'
end
# Gems used only for assets and not required
@@ -36,3 +37,5 @@ end
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
+
+gem "mocha", :group => :test
View
@@ -37,9 +37,15 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.3.1)
+ diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
+ factory_girl (3.1.1)
+ activesupport (>= 3.0.0)
+ factory_girl_rails (3.1.0)
+ factory_girl (~> 3.1.0)
+ railties (>= 3.0.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
@@ -83,11 +89,26 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ rspec-rails (2.9.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.9.0)
sass (3.1.15)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ shoulda-matchers (1.1.0)
+ activesupport (>= 3.0.0)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -108,10 +129,13 @@ PLATFORMS
DEPENDENCIES
coffee-rails (~> 3.2.1)
+ factory_girl_rails (~> 3.0)
jquery-rails
mocha
nifty-generators
rails (= 3.2.3)
+ rspec-rails (~> 2.9.0)
sass-rails (~> 3.2.3)
+ shoulda-matchers (~> 1.1.0)
sqlite3
uglifier (>= 1.0.3)
@@ -1,4 +1,6 @@
class PostsController < ApplicationController
+ rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
+
def index
@posts = Post.all
end
@@ -38,4 +40,10 @@ def destroy
@post.destroy
redirect_to posts_url, :notice => "Successfully destroyed post."
end
+
+ private
+
+ def record_not_found
+ redirect_to posts_url, :alert => "Couldn't find post"
+ end
end
@@ -1,3 +1,5 @@
class Post < ActiveRecord::Base
attr_accessible :title, :body
+
+ validates_presence_of :title, :body
end
@@ -1,19 +1,8 @@
<% title "Posts" %>
-<table>
- <tr>
- <th>Title</th>
- <th>Body</th>
- </tr>
- <% for post in @posts %>
- <tr>
- <td><%= post.title %></td>
- <td><%= post.body %></td>
- <td><%= link_to "Show", post %></td>
- <td><%= link_to "Edit", edit_post_path(post) %></td>
- <td><%= link_to "Destroy", post, :confirm => 'Are you sure?', :method => :delete %></td>
- </tr>
- <% end %>
-</table>
-
<p><%= link_to "New Post", new_post_path %></p>
+
+<% @posts.each do |post| %>
+ <h2><%= link_to post.title, post %></h2>
+ <p><%= sanitize(truncate(post.body, :length => 300)) %> <%= link_to "Read more ...", post %></p>
+<% end %>
@@ -1,16 +1,11 @@
<% title "Post" %>
-<p>
- <strong>Title:</strong>
- <%= @post.title %>
-</p>
-<p>
- <strong>Body:</strong>
- <%= @post.body %>
-</p>
+<h2><%= @post.title %></h2>
<p>
<%= link_to "Edit", edit_post_path(@post) %> |
<%= link_to "Destroy", @post, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "View All", posts_path %>
</p>
+
+<p><%= @post.body %></p>

0 comments on commit 4b47230

Please sign in to comment.