samedi 25 avril 2015

"undefined local variable or method `destroy_user_session_path'" (Authlogic)

I'm making a super basic rails app for practice, and I'm using Authlogic to implement user accounts. I've gotten so you can registr and log in but for some reason logging out isn't working. I get

undefined local variable or method `destroy_user_session_path' for #<#<Class:0x5bf5bd0>:0x41f19f0>

Extracted source:

10: <div id="user_nav">
11:    <% if current_user %>
12:       <%= link_to "Edit profile", edit_user_path(:current) %>
13:       <%= link_to "Logout(" + current_user.username + ")", destroy_user_session_path %>
14:    <% else %>
15:       <%= link_to "Register", new_user_path %>
16:       <%= link_to "Log in", new_user_session_path %>

I don't understand why it's not working, it's the default path made by resources isn't it? and "new_user_session_path" works fine. Here's my routing file:

Gnn::Application.routes.draw do
  get "users/new"

  get "users/edit"

  get "home/index"

  resources :categories

  resources :authors

  resources :users

  resources :user_sessions

  resources :articles do
    resources :comments 
  end

  # delete '/user_sessions/:id', to: 'user_sessions#destroy', as: 'logout'

  root :to => 'home#index'
end

I've tried manually creating the route with "delete '/user_sessions/:id', to: 'user_sessions#destroy'" and that didn't seem to work either. I'm at a standstill.

Aucun commentaire:

Enregistrer un commentaire