我是新手,我跟着一些教程來創建一個登錄系統。一切正常,直到我修改了一些東西(不知道是什麼),現在rails繼續將我重定向到404頁面。Rails保持渲染錯誤頁面
這是我在控制檯:
Started GET "/admin/users" for 127.0.0.1 at 2016-02-27 01:24:30 +0000
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by Admin::UsersController#index as HTML
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
Rendered errors/error_404.html.haml within layouts/application (12.2ms)
Completed 404 Not Found in 329ms (Views: 323.1ms | ActiveRecord: 0.4ms)
,這是該指數:
<h1> User's index </h1>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Email</th>
<th>Role</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.email %></td>
<td><%= user.role %> </td>
<td><%= time_ago_in_words(user.created_at) %> ago</td>
<td>
<% if can? :update, @user %>
<%= link_to 'Edit', edit_admin_user_path(user) %>
<% end %>
<!-- <% if can? :delete, @user %>
<%= link_to "delete", admin_user_path(user), :method => :delete, :confirm => "You sure?", :title => "Delete #{task.name}" %>
<% end %> -->
</td>
</tr>
<% end %>
</tbody>
</table>
<p> <%= link_to 'New user', new_admin_user_path %> </p>
你需要什麼其他的文件嗎?我真的不知道要發佈什麼。
這些都是在controlller /管理
application_controller.rb
class Admin::ApplicationController < ApplicationController
before_action :authorize
def current_user
@user ||= User.find(session[:current_user_id]) if session[:current_user_id]
end
def authorize
unless current_user
redirect_to '/login', alert: 'Please login'
end
end
end
users_controller.rb
class Admin::UsersController < Admin::ApplicationController
before_action :find_user_from_params, only: [:edit, :update, :destroy]
def index
@users = User.all
end
..
end
sessions_controller.rb
class Admin::SessionsController < Admin::ApplicationController
before_action :authorize, except: [:new, :create]
def new
end
def create
@user = User.find_by(email: params[:email]).try(:authenticate, params[:password])
if @user
session[:current_user_id] = @user.id
redirect_to admin_users_url, notice: 'You have successfully signed in'
else
flash[:alert] = 'There was a problem with your username or password'
render :new
end
end
def destroy
session[:current_user_id] = nil
redirect_to '/login', notice: 'You have successfully logged out'
end
end
路線。 rb
Rails.application.routes.draw do
get '/login' => 'admin/sessions#new'
get '/logout' => 'admin/sessions#destroy'
match "/403", to: "errors#error_403", via: :all
match "/404", to: "errors#error_404", via: :all
match "/422", to: "errors#error_422", via: :all
match "/500", to: "errors#error_500", via: :all
get :ie_warning, to: 'errors#ie_warning'
get :javascript_warning, to: 'errors#javascript_warning'
root to: "pages#index"
namespace :admin do
resources :sessions, only: [:new, :create, :destroy]
resources :users
end
end
這是用戶。我能夠看到/編輯/添加用戶,直到我修改'我不知道是什麼' –
@ developer033這根本不是真的。沒有任何理由讓您的模型命名空間與您的控制器相同。路由和控制器命名空間與模型或數據庫無關。 – meagar