Note that there are some explanatory texts on larger screens.

plurals
  1. POmake the comment(in the rails guide exmple) editable
    primarykey
    data
    text
    <p>I am learning rails by following the rails 3 guide.</p> <p>The blog application have ran now,however I want to make the comment editable,and make the update ,create form both in the post show page. so I make the following modifiation:</p> <p>post.show.htm.erb:</p> <pre><code>&lt;h2&gt;Comments&lt;/h2&gt; &lt;% @post.comments.each do |comment| %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= comment.commenter %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= comment.body %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Edit', edit_post_comment_path(@post,comment) %&gt;&lt;/td&gt; &lt;td&gt;&lt;%= link_to 'Destroy', post_comment_path(@post,comment), confirm: 'Are you sure?', method: :delete %&gt;&lt;/td&gt; &lt;/tr&gt; &lt;% end %&gt; &lt;/table&gt; &lt;h2&gt;Add a comment:&lt;/h2&gt; #here,I can not set the form_for property. &lt;%= form_for([@post,@comment],:url=&gt;post_comment_path) do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :commenter %&gt;&lt;br /&gt; &lt;%= f.text_field :commenter %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :body %&gt;&lt;br /&gt; &lt;%= f.text_area :body %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>The controller controller:</p> <pre><code>class CommentsController &lt; ApplicationController # GET /posts/1/comments/1/edit def edit #render json: params @post=Post.find(params[:post_id]) @comments=Comment.all @comment = Comment.find(params[:id]) render "/posts/show" end #other action omitted def show # I donot know what to do here end end </code></pre> <p>However I can not access the link:</p> <pre><code>http://localhost:3000/posts/1 </code></pre> <p>I get the error:</p> <pre><code>No route matches {:action=&gt;"show", :controller=&gt;"comments"} </code></pre> <p>In fact,as you can see I have the show action in CommentController.</p> <p>And,I wonder why it will access the comments#show action?</p> <p>This is my routes:</p> <pre><code> post_comments GET /posts/:post_id/comments(.:format) comments#index POST /posts/:post_id/comments(.:format) comments#create new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new edit_post_comment GET /posts/:post_id/comments/:id/edit(.:format) comments#edit post_comment GET /posts/:post_id/comments/:id(.:format) comments#show PUT /posts/:post_id/comments/:id(.:format) comments#update DELETE /posts/:post_id/comments/:id(.:format) comments#destroy 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 PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy home_index GET /home/index(.:format) home#index root / home#index </code></pre> <p>The <code>/posts/:id</code> will trigger <code>posts#show</code>. why <code>comments#show</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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