iam试图记住自3个月停止后如何编码,所以在我的新项目中尝试添加一个link_to到设备用户sign_in page..kept得到此错误。
NameError in Topics#index
undefined local variable or method `new_user_session' for #<#<Class:0x74e5db0>:0x54af248>
route.rb
Rails.application.routes.draw do
resources :topics
devise_for :admins, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)
devise_for :users
root 'topics#index'
这是我的路线
Prefix Verb URI Pattern Controller#Action
topics GET /topics(.:format) topics#index
POST /topics(.:format) topics#create
new_topic GET /topics/new(.:format) topics#new
edit_topic GET /topics/:id/edit(.:format) topics#edit
topic GET /topics/:id(.:format) topics#show
PATCH /topics/:id(.:format) topics#update
PUT /topics/:id(.:format) topics#update
DELETE /topics/:id(.:format) topics#destroy
new_admin_session GET /admin/login(.:format) active_admin/devise/sessions#new
admin_session POST /admin/login(.:format) active_admin/devise/sessions#create
destroy_admin_session DELETE|GET /admin/logout(.:format) active_admin/devise/sessions#destroy
admin_password POST /admin/password(.:format) active_admin/devise/passwords#create
new_admin_password GET /admin/password/new(.:format) active_admin/devise/passwords#new
edit_admin_password GET /admin/password/edit(.:format) active_admin/devise/passwords#edit
PATCH /admin/password(.:format) active_admin/devise/passwords#update
PUT /admin/password(.:format) active_admin/devise/passwords#update
admin_root GET /admin(.:format) admin/dashboard#index
batch_action_admin_admins POST /admin/admins/batch_action(.:format) admin/admins#batch_action
admin_admins GET /admin/admins(.:format) admin/admins#index
POST /admin/admins(.:format) admin/admins#create
new_admin_admin GET /admin/admins/new(.:format) admin/admins#new
edit_admin_admin GET /admin/admins/:id/edit(.:format) admin/admins#edit
admin_admin GET /admin/admins/:id(.:format) admin/admins#show
PATCH /admin/admins/:id(.:format) admin/admins#update
PUT /admin/admins/:id(.:format) admin/admins#update
DELETE /admin/admins/:id(.:format) admin/admins#destroy
admin_dashboard GET /admin/dashboard(.:format) admin/dashboard#index
batch_action_admin_users POST /admin/users/batch_action(.:format) admin/users#batch_action
admin_users GET /admin/users(.:format) admin/users#index
POST /admin/users(.:format) admin/users#create
new_admin_user GET /admin/users/new(.:format) admin/users#new
edit_admin_user GET /admin/users/:id/edit(.:format) admin/users#edit
admin_user GET /admin/users/:id(.:format) admin/users#show
PATCH /admin/users/:id(.:format) admin/users#update
PUT /admin/users/:id(.:format) admin/users#update
DELETE /admin/users/:id(.:format) admin/users#destroy
admin_comments GET /admin/comments(.:format) admin/comments#index
POST /admin/comments(.:format) admin/comments#create
admin_comment GET /admin/comments/:id(.:format) admin/comments#show
DELETE /admin/comments/:id(.:format) admin/comments#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
root GET / topics#index
index.erb
<div id="pre_header" class="visible-lg" style="background-color:#E4AB7E; height:5px;"></div>
<div id="header" class="container" style="background-color:#fff; background-image:none;">
<div class="row">
<!-- Logo -->
<div class="logo">
<%= link_to (image_tag 'logo.jpg',:style=>'padding:20px 50px;'), root_path %>
</div>
<!-- End Logo -->
<!-- Top Menu -->
<div class="col-md-12 margin-top-30">
<div id="hornav" class="pull-right visible-lg">
<ul class="nav navbar-nav">
<li><%= link_to 'Laman Utama', topics_path %></li>
<li><a href="index.html">Senarai Ilmu</a></li>
<li><a href="index.html">Hubungi Kami</a></li>
<li><a href="index.html">Info Lanjut</a></li>
<li><%= link_to 'Log Masuk',new_user_session %></li>
</ul>
</div>
</div>
<div class="clear"></div>
<!-- End Top Menu -->
</div>
</div>
<div id="pre_header" class="visible-lg" style="background-color:#E4AB7E; height:5px;"></div>
答案 0 :(得分:1)
我猜这是一个错字。链接中缺少path
。它将是new_user_session_path
<li><%= link_to 'Log Masuk',new_user_session_path %></li>