1
votes

I've been following Michael Hartl's rails tutorial but without testing (bad practice I know - I'm completely new to web programming having only dabbled in HTML and CSS before). I've reached the last chapter but I'm having problems with the user signup form. It's rendering properly in the browser but on submit I get the message

No route matches "/users/new"

Everything seems to be as it should be in the routes.rb file, and by entering users/new directly into the browser I can navigate to the correct page (the signup form) - but can't create new users.

There doesn't seem to be anything missed out from Michael Hartl's code

I've checked out the users controller as I figured it must be something to do with the 'new' or 'create' actions. It might also have to do with the number of "swap" files that seem to be being created every time I edit a file with Vim. I'm completely ignorant about what this means, but perhaps it's screwing things up. I've left these intact in my github push so you can see my incompetence.

Thanks for any help you can give me!

Here's the routes.rb file (everything else is on github at https://github.com/jnwb2/the_app):

TheApp::Application.routes.draw do

resources :users do

member do

  get :following, :followers

end

end

resources :sessions, :only => [:new, :create, :destroy]

resources :microposts, :only => [:create, :destroy]

resources :relationships, :only => [:create, :destroy]

match '/contact', :to => 'pages#contact'

match '/about', :to => 'pages#about'

match '/help', :to => 'pages#help'

match '/signup', :to => 'users#new'

match '/signin', :to => 'sessions#new'

match '/signout', :to => 'sessions#destroy'

root :to => 'pages#home'

end

1
When you are at the submission form, is your url /users/new? When using resources :modelname, it creates 7 route entries for you (GET -/users, GET - /users/:id, POST - /users, PUT - /users/:id, DELETE - /users/:id, GET - /users/new, GET - /users/:id/edit. You can always run rake routes from the terminal to see what's going on.agmcleod
Also, i just want to say that this isn't really the best way of doing things in some ways. All the extra actions in the controller here can really just be methods on a model: github.com/railstutorial/sample_app/blob/master/app/controllers/… The (following, followers) methods for example.agmcleod

1 Answers

2
votes

Found the answer. For one, i think you should stop following this tutorial. It seems to have a lot of bad practices going on. Try going to guides.rubyonrails.org instead. To fix your problem however, change line #8 in the users controller like so:

def new
  @title = "Sign up"
  @user = User.new
end

Sorry for all my extra comments from before, just ended up cloning your source to find the issue.