我正在尝试渲染Devise gem的登录视图,但是我收到一个错误,下面是我目前的代码:
这是我的views/users/shared/_links.html.erb:
<%- if controller_name != 'sessions' %>
<%= link_to "Sign in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if …Run Code Online (Sandbox Code Playgroud) 当我在我的页面上登录时,我自动转到路线:http:// localhost:3000/sessions/user
我收到这个错误:
Routing Error
No route matches "/sessions/user"
Run Code Online (Sandbox Code Playgroud)
我在users文件夹中创建了一个名为sessions_controller.rb的控制器,它是:
class Users::SessionsController < Devise::SessionsController
def new
redirect_to root_url, :notice => "You have been logged out."
end
def create
user = User.authenticate(params[:login], params[:encrypted_password])
if user
session[:user_id] = user.id
redirect_to root_url, :notice => "Logged in successfully."
else
flash.now[:alert] = "Invalid login or password."
render :action => 'new'
end
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "You have been logged out."
end
end
Run Code Online (Sandbox Code Playgroud)
我的路线档案:
Densidste::Application.routes.draw do
match 'user/edit' => …Run Code Online (Sandbox Code Playgroud)