mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 16:58:35 -04:00
Added edit/delete buttons to comment display
This commit is contained in:
@@ -25,7 +25,6 @@ class Ability
|
||||
can :create, Post
|
||||
can :update, Post, :author_id => member.id
|
||||
can :destroy, Post, :author_id => member.id
|
||||
|
||||
can :create, Comment
|
||||
can :update, Comment, :author_id => member.id
|
||||
can :destroy, Comment, :author_id => member.id
|
||||
|
||||
@@ -4,13 +4,21 @@
|
||||
.span1
|
||||
= render :partial => "shared/avatar", :locals => { :member => comment.author }
|
||||
.span7
|
||||
.post-meta
|
||||
.comment-meta
|
||||
Posted by
|
||||
= link_to comment.author.login_name, member_path(comment.author)
|
||||
at
|
||||
= comment.created_at
|
||||
|
||||
.post-body
|
||||
.comment-body
|
||||
:markdown
|
||||
#{ strip_tags comment.body }
|
||||
|
||||
- if can? :edit, comment or can? :destroy, comment
|
||||
.comment-actions
|
||||
- if can? :edit, comment
|
||||
= link_to 'Edit', edit_comment_path(comment), :class => 'btn'
|
||||
- if can? :destroy, comment
|
||||
= link_to 'Delete', comment, method: :delete, |
|
||||
data: { confirm: 'Are you sure?' }, :class => 'btn'
|
||||
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
= content_for :title, @comment.post.subject
|
||||
|
||||
%p#notice= notice
|
||||
|
||||
%p
|
||||
%b Post:
|
||||
= @comment.post_id
|
||||
%p
|
||||
%b Author:
|
||||
= @comment.author_id
|
||||
%p
|
||||
%b Body:
|
||||
= @comment.body
|
||||
= render :partial => "posts/single", :locals => { :post => @comment.post }
|
||||
|
||||
= link_to 'Edit', edit_comment_path(@comment)
|
||||
\|
|
||||
= link_to 'Back', comments_path
|
||||
%h2 Showing 1 comment
|
||||
|
||||
= render :partial => "single", :locals => { :comment => @comment }
|
||||
|
||||
=link_to "View all comments", post_path(@comment.post)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
.span1
|
||||
= render :partial => "shared/avatar", :locals => { :member => post.author }
|
||||
.span7
|
||||
- if subject
|
||||
- if defined?(subject)
|
||||
%h3= link_to strip_tags(post.subject), post
|
||||
|
||||
.post-meta
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
class RequireFieldsForComments < ActiveRecord::Migration
|
||||
def up
|
||||
change_table :comments do |t|
|
||||
t.change :post_id, :string, :null => false
|
||||
t.change :author_id, :string, :null => false
|
||||
t.change :body, :string, :null => false
|
||||
t.change :post_id, :integer, :null => false
|
||||
t.change :author_id, :integer, :null => false
|
||||
t.change :body, :text, :null => false
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
change_table :comments do |t|
|
||||
t.change :post_id, :string, :null => true
|
||||
t.change :author_id, :string, :null => true
|
||||
t.change :body, :string, :null => true
|
||||
t.change :post_id, :integer, :null => true
|
||||
t.change :author_id, :integer, :null => true
|
||||
t.change :body, :text, :null => true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
10
db/schema.rb
10
db/schema.rb
@@ -14,11 +14,11 @@
|
||||
ActiveRecord::Schema.define(:version => 20130208034248) do
|
||||
|
||||
create_table "comments", :force => true do |t|
|
||||
t.string "post_id", :null => false
|
||||
t.string "author_id", :null => false
|
||||
t.string "body", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "post_id", :limit => 255, :null => false
|
||||
t.integer "author_id", :limit => 255, :null => false
|
||||
t.text "body", :limit => 255, :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "crops", :force => true do |t|
|
||||
|
||||
@@ -2,18 +2,13 @@ require 'spec_helper'
|
||||
|
||||
describe "comments/show" do
|
||||
before(:each) do
|
||||
@comment = assign(:comment, stub_model(Comment,
|
||||
:post_id => 1,
|
||||
:author_id => 2,
|
||||
:body => "MyText"
|
||||
))
|
||||
controller.stub(:current_user) { nil }
|
||||
@comment = assign(:comment, FactoryGirl.create(:comment))
|
||||
render
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
rendered.should match(/1/)
|
||||
rendered.should match(/2/)
|
||||
rendered.should match(/MyText/)
|
||||
it "renders the comment" do
|
||||
rendered.should contain @comment.author.login_name
|
||||
rendered.should contain @comment.body
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user