Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bugs with blog and comment creation

  • Loading branch information...
commit 4e6f4ea9bbb86aad5a38739c21b2e2096e8907c8 1 parent 6409932
Aaron Wheeler authored
View
2  app/controllers/blogs.rb
@@ -36,7 +36,7 @@ def find_blog
@about = Category.first(:title => 'About')
@blog = Blog.last( :category_id.not => (@about ? @about.id : -1) )
else
- @blog = id ? Blog.first( id ) : Blog.first( :path_title => page_title, :year => year, :month => month )
+ @blog = id ? Blog.get( id ) : Blog.first( :path_title => page_title, :year => year, :month => month )
end
raise NotFound unless @blog
end
View
7 app/controllers/comments.rb
@@ -1,5 +1,5 @@
class Comments < Application
- provides :html, :rss
+ provides :html
before :login_required, :exclude => %w(new create)
def index
@@ -16,7 +16,7 @@ def show
end
def new
- provides :js
+ provides :js, :html
@blog = params[:blog_id] ? Blog.get( params[:blog_id] ) : nil
@comment = Comment.new( :blog_id => params[:blog_id] )
render
@@ -39,7 +39,8 @@ def create
redirect( '/' )
else
flash[:notice] = 'Thanks for sharing! Your comment will appear below.'
- redirect( url(:blog_by_date, @comment.reload.blog) )
+ b = @comment.reload.blog
+ redirect( url(:blog_by_date, b.year, b.month, b.path_title) )
end
else
render :new
View
2  app/helpers/comments_helper.rb
@@ -12,7 +12,7 @@ def comment_actions( comment )
email = '<a href="mailto:%s">Email</a>' % comment.author_email if logged_in? && comment.author_email
confirm = "return confirm('Are you certain you want to delete this comment?');"
delete = delete_button(
- :blog_comment, comment, 'Delete',
+ url(:blog_comment, comment.blog_id, comment.id), comment, 'Delete',
{:style => 'display:inline;'},
{:onclick => confirm, :style => 'font-size:.8em' }
)
View
2  app/views/admin/blogs/_form.html.haml
@@ -3,7 +3,7 @@
# Parameters:
# blog - blog object to edit or optionally create
-- action = blog.new_record? ? url(:new_admin_blog) : url(:edit_admin_blog, blog)
+- action = blog.new_record? ? url(:admin_blogs) : url(:edit_admin_blog, blog)
- form_for( :blog, :action => action ) do
- unless blog.new_record?
%input{ :name => '_method', :type => 'hidden', :value => "put" }
View
2  app/views/comments/_form.html.haml
@@ -7,7 +7,7 @@
- error_li = lambda { |err| "<li>#{ err.last.join('<br />') }</li>" }
= error_messages_for( @comment, error_li, 'errors' ) { |es| "<strong>#{es.size} problem(s) prevented your comment from saving:</strong>" }
-- action = @comment.blog_id ? url(:new_blog_comment, @comment) : url(:new_comment)
+- action = @comment.blog_id ? url(:blog_comments) : url(:new_comment)
- form_for( :comment, :action => action ) do
%dl{ :class => "#{ 'compact' if @comment.blog_id }"}
%dt= label_for( :author_name, 'Name*' )
View
2  app/views/comments/_index.html.haml
@@ -10,7 +10,7 @@
- for comment in blog.comments
- next if comment.new_record?
%li.dot
- = print_date( comment.created_at )
+ = print_date( comment.created_at ) unless comment.created_at.nil?
.comment
%strong= link_to_author( comment )
= comment.body
View
2  config/init.rb
@@ -53,7 +53,7 @@
dependencies "dm-aggregates"
require 'lib/object_ext'
-dependencies 'lib/merb_router_behavior_ext', 'lib/merb_exceptions_ext'
+#dependencies 'lib/merb_router_behavior_ext', 'lib/merb_exceptions_ext'
require File.join(File.dirname(__FILE__), '..', 'lib', 'authenticated_system/authenticated_dependencies') rescue LoadError
View
10 config/router.rb
@@ -32,15 +32,15 @@
resources :users
resources :sessions
+ namespace :admin do |admin|
+ resources :blogs
+ end
+
# RESTful routes
resources :blogs do |b|
- b.resources :comments
+ resources :comments
end
- namespace :admin do |admin|
- admin.resources :blogs
- end
-
resources :comments
match(%r{/(\d+)/(\d+)/([a-zA-Z\-]+)}).to(
Please sign in to comment.
Something went wrong with that request. Please try again.