Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Posts Controller
- def show
- @post = Post.find( params[:id] )
- end
- ## Comments Controller
- def create
- @post = Post.find( params[:post_id] )
- @comment = @post.comments.build( params[:comment] )
- @comment.skydiver_id = current_skydiver.id
- if @comment.save
- current_skydiver.has_role!(:owner, @comment)
- # FIXME Need to figure out why when comment is posted and redirect to same page, page isn't reloaded
- redirect_to post_path( @post )
- # render :location => post_path( @post )
- else
- render :action => 'new'
- end
- end
- ## posts/show.html.erb
- <div id="content">
- <h2 class="title"><%=h @post.title %></h2>
- <div class="post">
- <div class="top"></div>
- <div class="middle_back">
- <div id="blogPostHead">
- <%# Need to check for admin/author status here %>
- <% if current_skydiver %>
- Post Actions:
- [
- <%= link_to "Edit", edit_post_path( @post ) %> |
- <%= link_to 'Delete', post_path( @post ), :confirm => 'Are you sure?', :method => :delete %>
- ]
- <% end %>
- <br />
- <span id="postDate"><%=h @post.datetime %></span><br />
- <%= render :partial => 'category', :locals => { :categories => @post.categories } %><br />
- Posted by <span id="postAuthor"><%=h @post.skydiver.nickname %></span><br />
- <span id="postCommentCount"><%=h pluralize(@post.comments.count, "Comment") %></span>
- </div>
- <br />
- <div id="blogPostBody">
- <%=h @post.content %>
- </div>
- <h3>Comments</h3>
- <% unless flash[:notice].blank? %>
- <div id="commentNotification">
- <%= flash[:notice] %>
- </div>
- <% end %>
- <div id="postComments">
- <%= render :partial => 'comments/comment' %>
- </div>
- <% remote_form_for [@post, Comment.new] do |f| %>
- <p> <%= f.label :title, "Title" %><br />
- <%= f.text_field :title %>
- </p>
- <p> <%= f.label :content, "Tell us what you think:" %><br />
- <%= f.text_area :content %>
- </p>
- <p>
- <%= f.hidden_field :skydiver_id, :value => session[:skydiver] %>
- <%= f.submit "Add Comment" %>
- </p>
- <% end %>
- </div>
- </div>
- <div class="bottom"></div>
- </div>
- ## comments/_comment.html.erb
- <% @post.comments.each do |comment| %>
- <div id="postComment">
- <h4 class="commentTitle"><%=h comment.title %></h4>
- <% if current_skydiver and (current_skydiver.has_role?(:admin, nil) or current_skydiver.has_role?(:owner, comment) or current_skydiver.has_role?(:moderator, comment)) %>
- Comment Actions:
- [
- <%= link_to "Edit", edit_post_comment_path( comment ) %> |
- <%= link_to 'Delete', post_comment_path( comment ), :confirm => 'Are you sure?', :method => :delete %>
- ]
- <br />
- <% end %>
- <strong>Posted at <%= comment.created_at %></strong>
- by <%=h comment.skydiver.nickname %><br />
- <p class="commentContent"><%=h comment.content %></p>
- . . . . . . . . . . . . . . . . . . . .
- </div>
- <% end %>
Add Comment
Please, Sign In to add comment