Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialStephen Millward
7,731 PointsBuilding Social Features in Ruby on Rails, ActionView::Template::Error: undefined method `sessions_path'
I discovered this error when running rake test, in the adding state, test factories video, but from what I can tell it doesn't seem to be related to that, so it could have been in my code for some time now.
The error message I get is
1) Error:
test_that_/login_route_opens_the_login_page(CustomRoutesTest):ActionView::Template::Error: undefined method `sessions_path' for #<#<Class:0x000001016342a8>:0x00000104760598>
/Users/stephenmillward/Projects/treebook/app/views/devise/sessions/new.html.erb:3:in `_app_views_devise_sessions_new_html_erb___459108776128561212_2184902300'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/template.rb:145:in `block in render'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `block in instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/template.rb:143:in `render'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `block in instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/template_renderer.rb:45:in `render_template'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/template_renderer.rb:18:in `render'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/renderer.rb:36:in `render_template'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_view/renderer/renderer.rb:17:in `render'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/abstract_controller/rendering.rb:110:in `_render_template'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/metal/streaming.rb:225:in `_render_template'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/abstract_controller/rendering.rb:103:in `render_to_body'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/abstract_controller/rendering.rb:88:in `render'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/metal/rendering.rb:16:in `render'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activesupport-3.2.12/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
and the code from new.html.erb
<div class="row">
<div class="span4">
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: {class: "well"}) do |f| %>
<fieldset>
<legend>Sign In</legend>
<%= f.input :email %>
<%= f.input :password %>
<% if devise_mapping.rememberable? -%>
<div><%= f.input :remember_me, as: :boolean %></div>
<% end -%>
<div><%= f.button :submit, "Sign in" %></div>
</fieldset>
<% end %>
<%= render "devise/shared/links" %>
</div>
<div class="span8">
<h2>Signing in is easy and secure</h2>
</div>
</div>
I'm not sure what other code is relevant to this, but I will gladly copy and paste it on request Many Thanks.
3 Answers
Thomas Slater
5,094 PointsHm. I don't see anything wrong with this particular file, it looks like mine. My guess is that there's an issue in your routes.rb file (or maybe routes_test?)
Stephen Millward
7,731 PointsThank you for the reply, my routes.rb file looks like this:
Treebook::Application.routes.draw do
get "profiles/show"
as :user do
get '/register', to: 'devise/registrations#new', as: :register
get '/login', to: 'devise/sessions#new', as: :login
get '/logout', to: 'devise/sessions#destroy', as: :logout
end
devise_for :users, skip: [:sessions]
as :user do
get "/login" => 'devise/sessions#new', as: :new_user_session
post "/login" => 'devise/sessions#create', as: :new_user_session
delete "/logout" => 'devise/sessions#destroy', as: :destroy_user_session
end
resources :user_friendships
resources :statuses
get 'feed', to: 'statuses#index', as: :feed
root to: 'statuses#index'
get '/:id', to: 'profiles#show', as: 'profile'
end
and custom_routes_test.rb:
require 'test_helper'
class CustomRoutesTest < ActionDispatch::IntegrationTest
test "that /login route opens the login page" do
get '/login'
assert_response :success
end
test "that /logout route opens the logout page" do
get '/logout'
assert_response :redirect
assert_redirected_to '/'
end
test "that /register route opens the sign up page" do
get '/register'
assert_response :success
end
test "that a profile page works" do
get '/jasonseifer'
assert_response :success
end
end
again thanks for the any and all help
Frederick Pearson
Courses Plus Student 1,533 Pointschange this line: post "/login" => 'devise/sessions#create', as: :new_user_session
TO
post "/login" => 'devise/sessions#create', as: :user_session
I did the same mistake - you should call :user_session NOT :new_user_session in the post method for login