Note that there are some explanatory texts on larger screens.

plurals
  1. POI don't seem to understand NoMethodError in Comments#edit
    text
    copied!<p>I'm sorry but I am fairly new to Rails and I can't seem to understand what the problem is. I am building an online forum and want my users to not only be able to edit their own post but also any comments that they may create. I keep getting a: undefined method `comment_path' for #&lt;#:0x007fe5b6b0cbd0>. Any ideas?</p> <p>routes: </p> <pre><code>PostitTemplate::Application.routes.draw do root to: 'posts#index' get '/register', to: 'users#new' get '/login', to: 'sessions#new' post '/login', to: 'sessions#create' get '/logout', to: 'sessions#destroy' resources :users, only: [:create, :edit, :update] resources :posts, except: [:destroy] do member do post 'vote' end resources :comments, only: [:create, :edit, :update] do member do post 'vote' end end end resources :categories, only: [:new, :create] end </code></pre> <p>my comments edit.html.erb:</p> <pre><code>&lt;div class="page-header"&gt; &lt;h2&gt;Update Comment&lt;small&gt; - looks like you need some updating!&lt;/small&gt;&lt;/h2&gt; &lt;/div&gt; &lt;h3&gt;&lt;%= @post.description %&gt;&lt;/h3&gt; &lt;%= render 'shared_partials/errors', errors_obj: @comment %&gt; &lt;div class="well"&gt; &lt;%= form_for @comment do |f| %&gt; &lt;%= f.text_area :body, :class=&gt; "input", :placeholder=&gt; "Comment goes here", :rows =&gt; "6" %&gt; &lt;/br&gt; &lt;div class="button"&gt; &lt;%= f.submit "Create a comment", class: 'btn btn-primary' %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p>comments_controller:</p> <pre><code>class CommentsController &lt; ApplicationController before_action :require_user def create @post = Post.find(params[:post_id]) @comment = Comment.new(params.require(:comment).permit(:body)) @comment.post = @post @comment.creator = current_user if @comment.save flash[:notice] = "Your comment was created!" redirect_to post_path(@post) else render 'posts/show' end end def edit @comment = Comment.find(params[:id]) @post = Post.find(params[:post_id]) end def update @comment = Comment.find(params[:id]) if @comment.update(comment_params) flash[:notice] = "You updated your comment!" redirect_to post_comments_path else render :edit end end end </code></pre> <p>rake routes: </p> <pre><code> Prefix Verb URI Pattern Controller#Action root GET / posts#index register GET /register(.:format) users#new login GET /login(.:format) sessions#new POST /login(.:format) sessions#create logout GET /logout(.:format) sessions#destroy users POST /users(.:format) users#create edit_user GET /users/:id/edit(.:format) users#edit user PATCH /users/:id(.:format) users#update PUT /users/:id(.:format) users#update vote_post POST /posts/:id/vote(.:format) posts#vote vote_post_comment POST /posts/:post_id/comments/:id/vote(.:format) comments#vote post_comments POST /posts/:post_id/comments(.:format) comments#create edit_post_comment GET /posts/:post_id/comments/:id/edit(.:format) comments#edit post_comment PATCH /posts/:post_id/comments/:id(.:format) comments#update PUT /posts/:post_id/comments/:id(.:format) comments#update posts GET /posts(.:format) posts#index POST /posts(.:format) posts#create new_post GET /posts/new(.:format) posts#new edit_post GET /posts/:id/edit(.:format) posts#edit post GET /posts/:id(.:format) posts#show PATCH /posts/:id(.:format) posts#update PUT /posts/:id(.:format) posts#update categories POST /categories(.:format) categories#create new_category GET /categories/new(.:format) categories#new </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload