Reputation: 2396
I'm trying to use URL helpers in a 2.3.11 Ruby on Rails application, but I'm facing many problems with whatever the solution I try...
I've read a lot of "solutions" like including include ActionController::UrlWriter
before trying to get a path, but I get the same error every time:
>> app.users_path
NameError: undefined method `new_suggestion_path' for class `ActionController::Integration::Session'
I can't find the problem with this. I have a "suggestions" controller and a "new" action on it... Is there any other way to fix this and get a URL from console and/or Rake?
Upvotes: 2
Views: 2402
Reputation: 24337
You need to have resource routes defined for the named routes you are trying to access.
To make suggestion paths available in Rails 2.3, add a resource route config/routes.rb
:
ActionController::Routing::Routes.draw do |map|
map.resources :suggestions
end
That will define the following routes:
suggestions GET /suggestions(.:format) {:controller=>"suggestions", :action=>"index"}
POST /suggestions(.:format) {:controller=>"suggestions", :action=>"create"}
new_suggestion GET /suggestions/new(.:format) {:controller=>"suggestions", :action=>"new"}
edit_suggestion GET /suggestions/:id/edit(.:format) {:controller=>"suggestions", :action=>"edit"}
suggestion GET /suggestions/:id(.:format) {:controller=>"suggestions", :action=>"show"}
PUT /suggestions/:id(.:format) {:controller=>"suggestions", :action=>"update"}
DELETE /suggestions/:id(.:format) {:controller=>"suggestions", :action=>"destroy"}
Now you can use those routes in the console:
>> app.new_suggestion_path
=> "/suggestions/new"
>>
Upvotes: 3