I am using Ruby 1.8.7 with Rails 3.1. My application worked fine in Rails 3.0, but when I ran into Rails 3.1.4 all of my URL helpers broke!
After Googling, as a madman, over the past 2 days I refused, and it's time to ask for help. I don't think the problem is with my route.rb file, but something else is on the view / helper side.
I have the following on my routes:
resources :sessions
In my home view, I have the following link_to, which errors are missing:
<%= link_to "Login", new_session_path %>
When I do rake routes, I get the following output, so the path exists:
sessions GET /sessions(.:format) {:controller=>"sessions", :action=>"index"} POST /sessions(.:format) {:controller=>"sessions", :action=>"create"} new_session GET /sessions/new(.:format) {:controller=>"sessions", :action=>"new"} edit_session GET /sessions/:id/edit(.:format) {:controller=>"sessions", :action=>"edit"} session GET /sessions/:id(.:format) {:controller=>"sessions", :action=>"show"} PUT /sessions/:id(.:format) {:controller=>"sessions", :action=>"update"} DELETE /sessions/:id(.:format) {:controller=>"sessions", :action=>"destroy"}
When I go to / session / new in my browser, the page loads again, the route exists, but it is mistaken on the _path based URL:
<%= form_tag sessions_path, :method => :post do -%>
The error I am getting is as follows:
ActionView::Template::Error (undefined local variable or method `sessions_path' for #<#<Class:0x109cb8900>:0x109cab840>):
This should be something with the url_for helper as routes exist. What else should I look for?
UPDATE 1:
I added the following inside application_helper.rb:
include Rails.application.routes.url_helpers
Now when I get the following error:
In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers
Isn't that what I just did?
Update 2:
The following worked as Mr. Yoshiji said:
Rails.application.routes.url_helpers.sessions_path
Update 3:
I ran session_path again, removing some old Rails 2 plugins in the vendor directory.