i am getting an error with the best_in_place gem.
i want to edit my comments inside of the post show action since i render all comments there.
NoMethodError in Posts#show
Showing undefined method `erererer' for #<Comment:0x00007fc0ff1721c8>
comment view that i render in posts show page.
<!--<h3>there are <%#= pluralize(@comments.count, "comment") %></h3> -->
<% @comments.each do |comment| %>
<div class="media mb-5 ">
<% if comment.user.avatar.present? %>
<%= image_tag comment.user.avatar.url, class: 'rounded mr-3 d-flex', width: 42, height: 42%>
<% else %>
<%= random_avatar 42, "d-flex rounded mr-3"%>
<% end %>
<div class="media-body">
<div class="d-flex justify-content-between" />
<h5 class="mt-0"><a><%=link_to comment.user.username, user_path(comment.user) %></a></h5>
<p class="m-0 form-group">created at <%=time_ago_in_words(comment.created_at) %></p>
</div>
<%= best_in_place comment, comment.body, :as => :textarea %>
<% if current_user == comment.user %>
<span style="font-size: 15px;">
<%= link_to '', [comment.post, comment], method: :delete, data: {confirm: "sure?"}, class: ' btn btn-outline-danger btn-sm pull-right fa fa-trash-o' %>
<%= link_to '',edit_post_comment_path(comment.post, comment), class: 'btn btn-outline-warning btn-sm pull-right fa fa-pencil-square-o' %>
</span>
<% end %>
</div>
</div>
</section>
<%end%>
application.js
$(document).ready(function() {
/* Activating Best In Place */
$('.best_in_place').best_in_place();
});
comments_controller.rb
def update
if @comment.update(params[:comment].permit(:body))
format.html { redirect_to post_path(@post) }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { respond_with_bip(@comment) }
end
end
comment.rb
class Comment < ApplicationRecord
belongs_to :post
belongs_to :user
validates :body, presence: true
end
post.rb
class Post < ApplicationRecord
belongs_to :user
has_many :comments, dependent: :destroy
validates :title, presence: true, length: { minimum: 5 }
validates :body, presence: true, length: { minimum: 240 }
post.controller - add post controller code to question
class PostsController < ApplicationController
before_action :find_post, only: %i[destroy edit update comment_owner upvote downvote]
after_action :verify_authorized, only: [:edit, :update, :destroy, :create, :new]
layout '_app_nav'
def index
return redirect_to post_path(params[:post_id]) if params[:post_id]
return redirect_to user_path(params[:user_id]) if params[:user_id]
@post = Post.all.order('created_at DESC')
@posts = Post.all.order('created_at DESC')
@user = User.all
@posts = if params[:search]
else
Post.all.order('created_at DESC')
end
@comments = Comment.all
end
def new
@post = Post.new
end
def create
@post = current_user.posts.build(post_params)
authorize @post
if @post.save!
redirect_to @post
else
render 'new'
end
end
def show
@post = Post.find(params[:id])
@user = @post.user
@comments = Comment.where(post_id: @post).order('created_at DESC').paginate(:page => params[:page], :per_page => 5)
end
def edit
authorize @post
end
def update
authorize @post
if @post.update(post_params)
redirect_to @post, notice: 'updated.'
else
render :edit
end
end
end
def destroy
@post = Post.find(params[:id])
authorize @post
@post.destroy
redirect_to posts_path
end
private
def post_params
params.require(:post).permit(:title, :body, :user_id)
end
def find_post
@post = Post.find(params[:id])
end
UPDATE
This is the entire request that i get when trying to open posts#show
Started GET "/news/2" for 127.0.0.1 at 2018-07-30 03:12:49 +0200
(0.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by PostsController#show as HTML
Parameters: {"id"=>"2"}
Post Load (0.4ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 3], ["LIMIT", 1]]
Rendering posts/show.html.erb within layouts/_app_nav
Rendered comments/_form.html.erb (27.1ms)
Comment Load (0.9ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = 2 ORDER BY created_at DESC LIMIT $1 OFFSET $2 [["LIMIT", 5], ["OFFSET", 0]]
CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 3], ["LIMIT", 1]]
Rendered comments/_comment.html.erb (14.2ms)
Rendered posts/show.html.erb within layouts/_app_nav (442.2ms)
Completed 500 Internal Server Error in 509ms (ActiveRecord: 12.4ms)
ActionView::Template::Error (undefined method `erererer' for #<Comment:0x00007feba5717bc0>):
15:
16: <p class="m-0 form-group">created at <%=time_ago_in_words(comment.created_at) %></p>
17: </div>
18: <%= best_in_place comment, comment.body, :as => :textarea %>
19: <% if current_user == comment.user %>
20: <span style="font-size: 15px;">
21: <%= link_to '', [comment.post, comment], method: :delete, data: {confirm: "sure?"}, class: ' btn btn-outline-danger btn-sm pull-right fa fa-trash-o' %>
app/views/comments/_comment.html.erb:18:in `block in _app_views_comments__comment_html_erb___2232672375721569353_70325032812060'
app/views/comments/_comment.html.erb:5:in `_app_views_comments__comment_html_erb___2232672375721569353_70325032812060'
app/views/posts/show.html.erb:76:in `_app_views_posts_show_html_erb___2994099099531367002_70324990819000'
<%= best_in_place comment, comment.body, :as => :textarea %>
should be <%= best_in_place comment, :body, :as => :textarea %>