Rails -v 3.1.3 Ruby -v 1.8.7
我们目前正在研究Michael Hartl的Rails教程,并且遇到了访问设置并显示我们应用程序的所有用户页面的问题。在我们将will_paginate gem和administrator列添加到数据库之前,一切似乎都正常工作。在我们这样做之后,一切似乎都出了问题。
我们似乎无法弄清楚我们的代码出错的地方,以及哪些文件将连接到此位置。它可能是我们的UsersController的一个问题吗?
class UsersController < ApplicationController
before_filter :authenticate, :only => [:index, :edit, :update, :destroy]
before_filter :correct_user, :only => [:edit, :update]
before_filter :admin_user, :only => :destroy
def index
@title = "All users"
@users = User.paginate(:page => params[:page])
end
def new
@user = User.new
@title = "Sign up"
end
def show
@user = User.find(params[:id])
@title = @user.name
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App"
redirect_to @user
else
@title = "Sign up"
render 'new'
end
def edit
@user = User.find(params[:id])
@title = "Edit user"
end
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:success] = "Profile updated."
redirect_to @user
else
@title = "Edit user"
render 'edit'
end
def destroy
User.find(params[:id]).destroy
flash[:success] = "User destroyed."
redirect_to users_path
end
private
def authenticate
deny_access unless signed_in?
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_path) unless current_user?(@user)
end
end
end
end
错误也可以找到的头文件如下所示:
<header>
<div class="header_text">
Sample app
</div>
<nav class="round">
<ul>
<li><%= link_to "Home", root_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", users_path %></li>
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<% end %>
<li><%= link_to "Help", help_path %></li>
<% if signed_in? %>
<li><%= link_to "Sign out", signout_path, :method => :delete %></li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
非常感谢您的时间,两位新手rails开发人员都非常感谢所有答案。