开发者

Devise Sign in Sign Out link Error

开发者 https://www.devze.com 2023-04-08 10:22 出处:网络
I followed the wiki to create the links but get this error: Granted I am fairly new to Rails and Dev开发者_JAVA技巧ise

I followed the wiki to create the links but get this error: Granted I am fairly new to Rails and Dev开发者_JAVA技巧ise

uninitialized constant ApplicationController::UserSession

Extracted source (around line #1):

    1: <% if user_signed_in? %>
    2:   <li>
    3:   <%= link_to('Logout', destroy_user_session_path, :method => :delete) %>        
    4:   </li>

Trace of template inclusion: app/views/layouts/_header.html.erb, app/views/layouts/application.html.erb

    app/controllers/application_controller.rb:10:in `current_user_session'
    app/controllers/application_controller.rb:16:in `current_user'
    app/views/devise/menu/_login_items.html.erb:1:in`_app_views_devise_menu__login_items_html_erb__1251633497065791740_2169375180__3843613137737702562'
    app/views/layouts/_header.html.erb:13:in `_app_views_layouts__header_html_erb___2695761790912056148_2169430740_3591649723346667383'
    app/views/layouts/application.html.erb:10:in `_app_views_layouts_application_html_erb__2958864439808398489_2169528520__269406770402330689'


I had the same problem because I was migrating from authlogic to devise and I forgot to delete the authlogic specific methods in the application controller, like

private
def current_user_session
  return @current_user_session if defined?(@current_user_session)
  @current_user_session = UserSession.find
end

def current_user
  return @current_user if defined?(@current_user)
  @current_user = current_user_session && current_user_session.record
end

def require_user
  unless current_user
    store_location
    flash[:notice] = "You must be logged in to access this page"
    redirect_to new_user_session_url
    return false
  end
end

def require_no_user
  if current_user
    store_location
    flash[:notice] = "You must be logged out to access this page"
    redirect_to account_url
    return false
  end
end

def store_location
  session[:return_to] = request.request_uri
end

def redirect_back_or_default(default)
  redirect_to(session[:return_to] || default)
  session[:return_to] = nil
end

I hope this can help you.


Not sure if this is the problem, but have you tried setting :method => :delete to :method => :get? I would also suggest setting the link_to to button_to since you are trying to "do something" and not necessarily "go somewhere."

0

精彩评论

暂无评论...
验证码 换一张
取 消