views:

44

answers:

2

I have a simple conceptual question that has stumped me. I am trying to simply add a new view called 'Owner Show' to a Recipients controller that I have. This will be a new page that shows an owner of a recipient, the "for-owners-eyes-only" details about that recip. I've created the hello world erb and named it ownershow.html.erb. I've added a blank action to the controller called ownershow. I've created a new route called map.ownershow '/recipients/:action/:id" :action =>'ownershow'. It bombs. What am I doing wrong? Sounds like such a simple thing.

+1  A: 

It depends partially on what version of Rails you are using, but my guess is that your route is not quite correct.

I believe you need to declare the route as follows if you wanted a named route:

map.ownershow :controller => 'recipients', :action => 'ownershow'

However, a named route is quite a bit different than a regular route. A named route creates a mapping such that you can simply say myapp.com/ownershow and not myqpp.com/recipients/ownershow. You probably want to just add to a restful member route like so:

map.resources :recipients, :member => { :ownershow => :get }

The entire Rails routing guide is a very good read and helps explain a lot of these type of questions.

Topher Fangio
A: 
map.ownershow '/recipients/:action/:id" :action =>'ownershow'

should be

map.ownershow '/recipients/ownershow/:id", :controller => 'recipients', :action =>'ownershow'

The first item is the path you are trying to match and the params that are selected from it, the rest is values you are hard coding for all requests to that path (this is a simplification, but you get the idea.

You must specify at least the controller and action in one way or another (from the path matcher, or hard coded) for all routes.

cwninja