Skip to content

Commit

Permalink
Completed 'comments' implementation: fixed redirect; added anchor and…
Browse files Browse the repository at this point in the history
… comments count to tools; changed layout of "post tools" to be small div
  • Loading branch information
Joe Fiorini committed Apr 15, 2008
1 parent 301e868 commit 25bf41b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
4 changes: 3 additions & 1 deletion app/controllers/comments_controller.rb
@@ -1,4 +1,6 @@
class CommentsController < ResourceController::Base
belongs_to :post


create.wants.html { redirect_to @post }

end
7 changes: 4 additions & 3 deletions app/views/posts/_post.html.haml
@@ -1,6 +1,6 @@
.post
%img{:src => "/images/icons/24-book-blue-mark.png"}
%h2= post.title
%h2= link_to post.title, post
%h3#tags
on
= format_date_long(post.created_at)
Expand All @@ -12,8 +12,9 @@
%hr
.post-content
= post.body
%fieldset
%legend tools
#tools
= link_to "#{post.comments.length} comments", comments_for_post_path(post.id)
&ndash;
%a{:href => "#"} permalink
&ndash;
%a{:href => "#"} save to del.icio.us
Expand Down
1 change: 1 addition & 0 deletions app/views/posts/show.html.haml
@@ -1,5 +1,6 @@
= render_partial 'post', @post

%a{:name => 'comments'}
.comments
- @post.comments.each do |c|
.comment
Expand Down
32 changes: 1 addition & 31 deletions config/routes.rb
Expand Up @@ -4,6 +4,7 @@
map.home 'home', :controller => 'posts'
map.login 'login', :controller => 'sessions', :action => 'new'
map.logout 'logout', :controller => 'sessions', :action => 'destroy'
map.comments_for_post 'posts/:id', :controller => 'posts', :action => 'show', :anchor => 'comments'

map.resources :posts, :has_many => :comments

Expand All @@ -15,37 +16,6 @@
map.open_id_complete 'session', :controller => "sessions", :action => "create", :requirements => { :method => :get }
map.resource :session

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

# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action

# Sample of named route:
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
# This route can be invoked with purchase_url(:id => product.id)

# Sample resource route (maps HTTP verbs to controller actions automatically):
# map.resources :products

# Sample resource route with options:
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }

# Sample resource route with sub-resources:
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller

# Sample resource route within a namespace:
# map.namespace :admin do |admin|
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
# admin.resources :products
# end

# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
# map.root :controller => "welcome"

# See how all your routes lay out with "rake routes"

# Install the default routes as the lowest priority.
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end

0 comments on commit 25bf41b

Please sign in to comment.