问题localhost:3000/users/ 不会显示
当我第一次尝试通过 rails 教程时,我谦虚地进入。我在第 10 章,我已经解决了 5 个小时的问题。当我尝试访问 localhost:3000/users/ 时,我收到一个错误(我相信这与 factory_girl 有关),它解释了@users 变量为空并且我忘记为 will_paginate 传递一个集合对象。
我目前在第 10 章第 10.23 节,每次运行时:
$ bundle exec rake db:reset$ bundle exec rake db:populate
$ bundle exec rake db:test:prepare
我得到一个错误解释
耙中止!工厂已注册:微博
这是我第二次尝试本章,因为我第一次遇到问题并从第9章开始。请帮助并在提供指导时清晰详细。我很高兴发布任何有用的文件。
这是我的 index.html.erb - 我将这些保存为 HTML,是否应该将它们保存为 ruby 文件?
<% provide(:title, 'All users') %>
<h1>All users</h1>
<%= will_paginate %>
<ul class="users">
<%= render @users %>
</ul>
<%= will_paginate %>
这是我的用户控制器
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update, :destroy]
before_filter :correct_user, only: [:edit, :update]
before_filter :admin_user, only: :destroy
def show
@user = User.find(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
end
end
def new
@user = User.new
end
def index
@title = "All users"
@users = User.paginate(:page => params[:page])
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Do more of the things you love!"
redirect_to @user
else
render 'new'
end
end
def edit
end
def update
if @user.update_attributes(params[:user])
flash[:success] = "Profile updated"
sign_in @user
redirect_to @user
else
render 'edit'
end
end
def destroy
User.find(params[:id]).destroy
flash[:success] = "User destroyed."
redirect_to users_url
end
private
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_path) unless current_user?(@user)
end
def admin_user
redirect_to(root_path) unless current_user.admin?
end