Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDon Neethling
6,164 PointsNoMethodError in Contacts#edit
This is what I have in my routes.rb file
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get '/contacts/:id/edit', to: 'contacts#edit'
get '/contacts', to: 'contacts#index', as: 'home'
get '/contacts/new', to: 'contacts#new', as: 'new'
get '/contacts/:id', to: 'contacts#show', as: 'shows'
post '/contacts', to: 'contacts#create'
end
and this is the content of my edit.html.erb file
<%= form_for(@contact) do |c| %>
<div>
<%= c.label 'First Name' %>
<%= c.text_field :fname %>
</div>
<div>
<%= c.label 'Last Name' %>
<%= c.text_field :lname %>
</div>
<div>
<%= c.label :number %>
<%= c.text_field :number %>
</div>
<div>
<%= c.submit %>
</div>
<% end %>
I get the following error message when I try to load the following page http://localhost:3000/contacts/1/edit
NoMethodError in Contacts#edit
Showing /Users/donovanneethling/Ruby/addressbook/app/views/contacts/edit.html.erb where line #1 raised:
undefined method `contact_path' for #<#<Class:0x007fca54438cf0>:0x007fca555632c8> Did you mean? contacts_path
Extracted source (around line #1):
However when I add the path helper to the route as below, the page loads
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get '/contacts/:id/edit', to: 'contacts#edit', as: 'contact'
get '/contacts', to: 'contacts#index', as: 'home'
get '/contacts/new', to: 'contacts#new', as: 'new'
get '/contacts/:id', to: 'contacts#show', as: 'shows'
post '/contacts', to: 'contacts#create'
end
Please advise