Guest User

Untitled

a guest
Jul 14th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. ## Posts Controller
  2. def show
  3. @post = Post.find( params[:id] )
  4. end
  5.  
  6. ## Comments Controller
  7. def create
  8. @post = Post.find( params[:post_id] )
  9. @comment = @post.comments.build( params[:comment] )
  10. @comment.skydiver_id = current_skydiver.id
  11. if @comment.save
  12. current_skydiver.has_role!(:owner, @comment)
  13. # FIXME Need to figure out why when comment is posted and redirect to same page, page isn't reloaded
  14. redirect_to post_path( @post )
  15. # render :location => post_path( @post )
  16. else
  17. render :action => 'new'
  18. end
  19. end
  20.  
  21. ## posts/show.html.erb
  22. <div id="content">
  23. <h2 class="title"><%=h @post.title %></h2>
  24. <div class="post">
  25. <div class="top"></div>
  26. <div class="middle_back">
  27.  
  28. <div id="blogPostHead">
  29. <%# Need to check for admin/author status here %>
  30. <% if current_skydiver %>
  31. Post Actions:
  32. [
  33. <%= link_to "Edit", edit_post_path( @post ) %> |
  34. <%= link_to 'Delete', post_path( @post ), :confirm => 'Are you sure?', :method => :delete %>
  35. ]
  36. <% end %>
  37. <br />
  38. <span id="postDate"><%=h @post.datetime %></span><br />
  39. <%= render :partial => 'category', :locals => { :categories => @post.categories } %><br />
  40. Posted by <span id="postAuthor"><%=h @post.skydiver.nickname %></span><br />
  41. <span id="postCommentCount"><%=h pluralize(@post.comments.count, "Comment") %></span>
  42. </div>
  43. <br />
  44. <div id="blogPostBody">
  45. <%=h @post.content %>
  46. </div>
  47.  
  48. <h3>Comments</h3>
  49. <% unless flash[:notice].blank? %>
  50. <div id="commentNotification">
  51. <%= flash[:notice] %>
  52. </div>
  53. <% end %>
  54. <div id="postComments">
  55. <%= render :partial => 'comments/comment' %>
  56. </div>
  57.  
  58. <% remote_form_for [@post, Comment.new] do |f| %>
  59. <p> <%= f.label :title, "Title" %><br />
  60. <%= f.text_field :title %>
  61. </p>
  62. <p> <%= f.label :content, "Tell us what you think:" %><br />
  63. <%= f.text_area :content %>
  64. </p>
  65. <p>
  66. <%= f.hidden_field :skydiver_id, :value => session[:skydiver] %>
  67. <%= f.submit "Add Comment" %>
  68. </p>
  69. <% end %>
  70.  
  71. </div>
  72. </div>
  73. <div class="bottom"></div>
  74. </div>
  75.  
  76.  
  77. ## comments/_comment.html.erb
  78. <% @post.comments.each do |comment| %>
  79. <div id="postComment">
  80. <h4 class="commentTitle"><%=h comment.title %></h4>
  81. <% if current_skydiver and (current_skydiver.has_role?(:admin, nil) or current_skydiver.has_role?(:owner, comment) or current_skydiver.has_role?(:moderator, comment)) %>
  82. Comment Actions:
  83. [
  84. <%= link_to "Edit", edit_post_comment_path( comment ) %> |
  85. <%= link_to 'Delete', post_comment_path( comment ), :confirm => 'Are you sure?', :method => :delete %>
  86. ]
  87. <br />
  88. <% end %>
  89. <strong>Posted at <%= comment.created_at %></strong>
  90. by <%=h comment.skydiver.nickname %><br />
  91. <p class="commentContent"><%=h comment.content %></p>
  92. . . . . . . . . . . . . . . . . . . . .
  93. </div>
  94. <% end %>
Add Comment
Please, Sign In to add comment