我对嵌套资源应该如何工作以及如何访问它们感到困惑这里我的模型有问题
event eventcomments
id id
Title body
Content event_id
...
这是我的路线文件
resources :events do
resources :eventcomments
end
end
这里的关系
Article
has_many :eventcomments
Comments
belongs_to event
但是当我在事件的 show.html.erb 中时,我无法获得编辑评论的链接。这里产生了耙子路线
edit_event_eventcomment GET /events/:event_id/eventcomments/:id/edit(.:format) eventcomments#edit
和我的链接
<h2>Comments</h2>
<div>
<% @comments.each do |comment| %>
<div>
<%= image_tag (comment.customer.avatar).url(:thumb) %>
<%= comment.customer.incomplete_name %> said:
<%= comment.description %>
<div>Posted: <%= time_ago_in_words(comment.created_at) %></div>
<% if current_customer.isadmin? %>
<%= link_to 'Edit', edit_event_eventcomment_path(@event) %>
<%= link_to 'Destroy', '#' %>
<% end %>
</div><br />
这是我得到的错误
NoMethodError in Eventcomments#edit
Showing /home/jean/rail/voyxe/app/views/eventcomments/_form.html.erb where line #1 raised:
undefined method `eventcomment_path' for #<#<Class:0xb5e73d84>:0xb5e7c8f8>
Extracted source (around line #1):
1: <%= form_for(@eventcomment) do |f| %>
2: <% if @eventcomment.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@eventcomment.errors.count, "error") %> prohibited this eventcomment from being saved:</h2>