views:

58

answers:

4

I'm new to Ruby on Rails, and I'm sure I'm just missing something simple and stupid, but I can't figure out how to get my 'account/signup' action working.

This is what I have in my routs file:

map.connect ':controller/:action'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
map.root :controller => "home"

I've added this to my accounts controller:

def signup
  @account = Account.new

  respond_to do |format|
    format.html # signup.html.erb
    format.xml  { @account }
  end
end

And I've added signup.html.erb to the accounts views folder.

Yet when I go to it in the browser I get this error:

ActiveRecord::RecordNotFound in AccountsController#show Couldn't find Account with ID=signup

What am I doing wrong?

+2  A: 

Add the following code right on top of your routes.rb file

ActionController::Routing::Routes.draw do |map|
  map.connect 'account/signup', :controller => 'account', :action => 'signup'
  ...
  ...
  ...
end

Also I think you mean Account and not Accounts.

Warren Noronha
+2  A: 

Here's a tip:

If you run rake routes it'll show you all the possible routes for your app. It should then be obvious depending on what URL you are entering whether it'll be correctly resolved or not.

For a good overview of routes read this guide. There's really a lot of stuff you can do with routes so it's worth taking some time to read it.

JRL
+1  A: 

If you want to follow the REST model, you controller should be called sessions and your signup action should be new, so in your routes you could do :

map.resources :sessions

This website is highly recommended to all newcomers to Rails :

http://guides.rubyonrails.org/

Mike
A: 

The following will do as well when added to the do |map| section of routes.rb

map.resource :account, :member => {:signup => :get}

Will create the standard routes for your accounts controller, as well as add the new route account/signup. It also provides the usual url helpers in addition to signup_account_url and signup_account_path

EmFi