Don Neethling

Joined

100 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in NoMethodError in Contacts#edit

Hi all, I am new to Ruby as well as Rails
I am working my way through a treehouse course and I have hit a bit of an obstacle.

This is what my routes file looks like
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', ato: 'contacts#new', as: 'new'
  get '/contacts/:id', to: 'contacts#show', as: 'shows'
  post '/contacts', to: 'contacts#create'
end

the method in the controller is as follows
    def edit
        @contact = Contact.find(params[:id])
    end
and this is what the edit.html.erb file looks like
<%= 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 %>

as is this will result in the following when I I try to load the edit page (example: http://localhost:3000/contacts/1/edit)


NoMethodError in Contacts#editShowing 

/Users/donovanneethling/Ruby/addressbook/app/views/contacts/edit.html.erbwhere line #1raised:

undefined method `contact_path' for #<#<Class:0x007fca54438cf0>:0x007fca57e82a78>
Did you mean?  contacts_path




However when I amend the edit route as follows
get '/contacts/:id/edit', to: 'contacts#edit', as: 'contact'
 the page loads correctly.

Would someone be able to explain this to me, I am guessing it has something to do with form_for...


Posted in Rails stopped listening on localhost

I am a novice rails user, I have been plodding along without too much trouble until today.
I use a Mac (just stating that in case my environment needs to be considered)
After creating a new rails app and running bin/rails s I would usually be greeted by the following

don9000:apple donovanneethling$ bin/rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.4.1-p111), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop

except to would reflect that it was listening on localhost instead of 0.0.0.0

I was busy coding when this changed all of a sudden
Nothing loads when I try to browse to 0.0.0.0:3000.

I recall having the same issue a while ago and realised I was running rails -s instead of bin/rails -s but in this case I experience the same regardless of the command that I run

please advise

Don

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.