I just followed the following tutorial and works great. http://www.communityguides.eu/articles/6
However one thing his hard for me and that is an edit.
I called my link_to edit has follow
<%= link_to 'Edit', edit_article_comment_path(@article, comment) %>
Which then bring me to a page with error and not sure why.
NoMethodError in Comments#edit
Showing /home/jean/rail/voyxe/app/views/comments/_form.html.erb where line #1 raised:
undefined method `comment_path' for #<#<Class:0xa8f2410>:0xb65924f8>
Extracted source (around line #1):
1: <%= form_for(@comment) do |f| %>
2: <% if @comment.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
Now here the form in comments edit
<%= form_for(@comment) do |f| %>
<% if @comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
<% @comment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Here are the controller
Article controller show
@article = Article.find(params[:id])
@comments = @article.comments.find(:all, :order => 'created_at DESC')
Comment controller edit
def edit
@comment = Comment.find(params[:id])
end
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…