Created
December 9, 2013 00:20
-
-
Save morenoh149/7865544 to your computer and use it in GitHub Desktop.
creating comments on posts. users have many posts. many users may comment on a post.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentsController < ApplicationController | |
before_filter :authenticate_user! | |
def index | |
@comments = Post.includes(:comments).find(params[:post_id]) | |
end | |
def create | |
@post = Post.find(params[:post_id]) | |
@comment = @post.comments.build(comment_params) | |
@comment.user_id = current_user.id | |
if @comment.save | |
format.html { redirect_to current_user_path } | |
else | |
format.html { render action: 'new' } | |
end | |
end | |
def destroy | |
@comment = Comment.find(params[:id]) | |
if @comment.user_id == current_user.id | |
@comment.destroy | |
end | |
if request.xhr? # this is the ajax check | |
else | |
end | |
end | |
private | |
def comment_params | |
params.require(:comment).permit(:text) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArgumentError in CommentsController#create | |
too few arguments | |
Extracted source (around line #17): | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
format.html { redirect_to current_user_path } | |
else | |
format.html { render action: 'new' } | |
end | |
end | |
Rails.root: /Users/harrymoreno/programming/railsdev/dezzmo/dezzmo0003 | |
Application Trace | Framework Trace | Full Trace | |
app/controllers/comments_controller.rb:17:in `format' | |
app/controllers/comments_controller.rb:17:in `create' | |
Request | |
Parameters: | |
{"utf8"=>"✓", | |
"authenticity_token"=>"4WHeEQgS8Qsz2XR1dMPXdtnVOlJ0zOykNKBkjKBNVdM=", | |
"comment"=>{"text"=>""}, | |
"commit"=>"Critique", | |
"post_id"=>"1"} | |
Toggle session dump | |
_csrf_token: "4WHeEQgS8Qsz2XR1dMPXdtnVOlJ0zOykNKBkjKBNVdM=" | |
session_id: "7e11ef14064a877048e56cead0f06889" | |
warden.user.user.key: [[1], "$2a$10$azongMNydZO.mjUV8EqePu"] | |
Toggle env dump | |
GATEWAY_INTERFACE: "CGI/1.1" | |
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" | |
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch" | |
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8" | |
HTTP_CACHE_CONTROL: "no-cache" | |
HTTP_PRAGMA: "no-cache" | |
REMOTE_ADDR: "127.0.0.1" | |
REMOTE_HOST: "127.0.0.1" | |
SERVER_NAME: "localhost" | |
SERVER_PROTOCOL: "HTTP/1.1" | |
Response | |
Headers: | |
None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li class="flip"> | |
<div class="card-container"> | |
<div class="card"> | |
<div class="front"> | |
<div class="card-top-bar"> | |
<span class="pull-left" style="padding-left: 20px;"> | |
<%= image_tag feed_item.user.avatar_url(:icon).to_s, class: "avatar-img" %> | |
<%= link_to feed_item.user.username, user_path(feed_item.user) %> | |
</span> | |
</div> | |
<%= image_tag feed_item.image_url(:thumb).to_s, class: "card-img" %> | |
<%= fa_icon "reply 2x", class:"flip-top-front flip-btn" %> | |
<%= fa_icon "reply rotate-180", class:"flip-bottom-front flip-btn" %> | |
<p class="post-title"><%= feed_item.title %></p> | |
</div> | |
<div class="back"> | |
<div class="row"> | |
<div class="back-user col-xs-12 col-sm-12"> | |
<div class="row"> | |
<div class="col-xs-4 col-sm-4"> | |
<%= image_tag feed_item.user.avatar_url(:thumb).to_s, class: "avatar-img", | |
style: "padding-left: 20px;" %> | |
</div> | |
<div class="col-xs-8 col-sm-8"> | |
<%= link_to feed_item.user.username, user_path(feed_item.user) %> | |
<br> | |
<strong><%= feed_item.title %></strong> | |
</div> | |
</div> | |
</div> | |
<div class="back-about col-xs-12 col-sm-12"> | |
<strong>About:</strong> | |
<%= feed_item.about %> | |
</div> | |
<div class="back-comments"> | |
<%= form_for @comment, url: post_comments_path(feed_item) do |f| %> | |
<%= f.text_area :text %> | |
<%= f.submit "Critique" %> | |
<% end %> | |
<strong>Comments:</strong> | |
<% feed_item.comments.each do |c| %> | |
<div> | |
<%= image_tag c.user.avatar_url(:icon).to_s %> | |
<%= link_to c.user.username, user_path(c.user) %>: | |
<%= c.text %> | |
<small><%= time_ago_in_words(c.created_at) %> ago</small> | |
</div> | |
<% end %> | |
</div> | |
<%= link_to user_post_path(@user, feed_item), method: 'delete', class: "delete-btn" do %> | |
Delete <%= fa_icon "times-circle" %> | |
<% end %> | |
<%= fa_icon "reply", class:"flip-top-back flip-btn" %> | |
<%= fa_icon "reply 2x rotate-180", class:"flip-bottom-back flip-btn" %> | |
</div> | |
</div> | |
</div> | |
</li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment