views:

470

answers:

4

I used scaffold to create a model and controller. It worked well. Then I started editing/removing some of the controller actions. So I made participations/new > participations/signup.

This does not work, it says "Unkown action" but it does say it has the action signup. Funny thing is if I go to Participations/signup using a capital P. Then it does work!

I also did Rake routes where participations/new still shows up even though I edited the method name.

IS there anything special I need to do to define actions?

A: 

If I remember correctly, RoR is case sensitive, so make sure your controller starts with a lowercase "p" and any actions also start with a lowercase letter. give that a try

FailBoy
+3  A: 

You need to edit the config/routes.rb file, too and tell Rails how should it handle the participations/signup route. In your routes.rb file you should have something like:

map.resources :participations

you will have to add a new rule for this:

map.signup '/participations/signup', :controller => 'participations', :action => 'new'

Tha should do it.

Milan Novota
+1  A: 

It's not unusual to maintain the standard RESTful routes and controller actions and map user-friendly alternate paths onto them. For example, in your case:

map.signup '/signup', :controller => 'participations', :action => 'new'

Your users could then access participations#new at the very friendly URL http://foo.com/signup (if, of course, your site were at foo.com). In your controllers and views you would refer to this route as signup_path or signup_url.

Abie
+2  A: 

If you are using resources then it is quite easy to fix.

that is, if you have

map.resources :participations

and you don't want to use named routes like the other answers suggests, you have the following options:

  • To change the /participations/new to /participations/signup, but still keep the new as the action in the controller

    map.resources :participations, :path_names => {:new => 'signup'}

  • To use /participations/signup, and the action signup in the controller:

    map.resources :participations, :collection => {:signup => [:get, :post]}

If you also want to limit so that they can't use the /participations/new action, add :except => :new to the above statement

I suggest that you use this way unless you have a reason for using the named routes since it (at least it's my opinion) gives a cleaner routes.rb.

Just keep in mind that the routes.rb are being read from top till bottom, so the first matching route will be the one being used.

Jimmy Stenke