views:

31

answers:

3

In my UserController I have:

def join
end

I have a join.html.erb in my /views/user/ folder.

My routes has a :

resources :user

When I go to:

http://localhost:3000/user/join

I get:

The action 'show' could not be found for UserController

A: 

Place:

def show
end

in your UserController.

To be certain:

app/controllers/users_controller.rb

def join
end

app/views/users/join.html.erb

config/routes.rb

resources :users
tinifni
but /user/join I want to use the 'join' action in the usercontroller, not the 'show' action.
Blankman
I'm just suggesting that you fix the error you're getting first. Maybe your answer will be more visible once you do.
tinifni
Sorry if my answer is lacking. I'm still new to RoR. I'm just offering what little I know to try and help out. Hope you find your answer!
tinifni
+4  A: 

Re: why isn't the join action found?

To answer your specific question, what's happening is that you want to have an action "join" for your User model.

Your problem is that you haven't defined a route matching the url http://localhost:3000/user/join

The line resources :user in your routes file only defines routes for the seven standard rest verbs/actions:

index, new, create, show, edit, update, destroy

See: http://apidock.com/rails/ActionController/Resources/resources

Added: to fix, you'll need to add an explicit or generic route. Routing docs

Added: Re: why am I seeing the error message re show? To be ultra-precise, the route selector "GET /usr/:id" (created by your resource call) is being used to select the SHOW action for the User resource. The :id value is being set to "join". Since you don't have a Show method defined in your controller, that's the error that you're seeing.

Larry K
The generic route Larry mentions would look like this: `resources :user do member do get 'join' endend`
Jeremy
+1  A: 

You're using resources, but have a non-REST action, so you need to add the join action to the route with the appropriate HTTP verb:

map.resources :users, :member => { :join => :get }
Jeremy Weiskotten