I've set up a resource in routes.rb
:
map.resource :papers
which is reflected in the output of rake routes
:
new_papers GET /papers/new(.:format) {:controller=>"papers", :action=>"new"}
edit_papers GET /papers/edit(.:format) {:controller=>"papers", :action=>"edit"}
papers GET /papers(.:format) {:controller=>"papers", :action=>"show"}
PUT /papers(.:format) {:controller=>"papers", :action=>"update"}
DELETE /papers(.:format) {:controller=>"papers", :action=>"destroy"}
POST /papers(.:format) {:controller=>"papers", :action=>"create"}
The problem arises when I attempt to redirect to a named route within a controller action. This is an excerpt from the create
action for the Paper resource. It should redirect the user to the show
action of the paper
controller on a successful save.
if @paper.save
redirect_to @paper
else
render :action => 'new'
end
The exception that arises is: undefined method 'paper_url'
, suggesting that the controller cannot see the named route. These helper methods will work in views, however.
As far as I can tell, this is the same way a Rails scaffold sets up a resource, so I can't find what's wrong. What am I missing here?