I am confused on how nested resources should works and how can i access them
Here my model in question
event eventcomments
id id
Title body
Content event_id
...
Here my route file
resources :events do
resources :eventcomments
end
end
Here the relationship
Article
has_many :eventcomments
Comments
belongs_to event
But when i am in show.html.erb of events, I can’t have the link to edit the comment. here the rake route produced
edit_event_eventcomment GET /events/:event_id/eventcomments/:id/edit(.:format) eventcomments#edit
and my link to
<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 />
Here the error i am getting
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>
You are only passing an
Eventinstance to theedit_event_eventcomment_pathmethod and you should be passing theEventcommentinstance also.Try with
edit_event_eventcomment_path(@event, comment)Note: Rename your
Eventcommentclass toEventCommentor justComment.