我目前正在使用devise + omniauth身份验证来注册用户。但是当我点击索引链接时,它只显示1个用户。我目前有大约5个演示用户注册。有谁知道如何显示其他4个用户以及更多会注册的用户?
这些是我的用户和控制器代码行
Application_contoller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password, :last_name, :first_name) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:first_name, :last_name,:profile_name,:email, :password, :name) }
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:name, :email, :password, :last_name, :first_name) }
devise_parameter_sanitizer.for(:account_update) { |u|
u.permit(:password, :password_confirmation, :current_password, :name)
}
end
end
user.rb
class User < ActiveRecord::Base
has_many :authentications
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauth_providers => [:facebook]
attr_accessible :email, :password, :password_confirmation, :name
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.email = auth.info.email
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
def self.new_with_session(params, session)
if session["devise.user_attributes"]
new(session["devise.user_attributes"], without_protection: true ) do |user|
user.attributes = params
user.valid?
end
else
super
end
end
def password_required?
super && provider.blank?
end
def email_required?
super && provider.blank?
end
end
users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def index
@users = User.paginate(page: params[:page])
end
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update_attributes(user_params)
flash[:success] = "Profile updated"
redirect_to @user
else
render 'edit'
end
end
private
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
end
end
应用程序/视图/用户/ index.html.erb
<% provide(:title, 'All users') %>
<h1>All users</h1>
<%= will_paginate %>
<ul class="users">
<%= render @users %>
</ul>
<%= will_paginate %>
应用程序/视图/用户/ _user.html.erb
<li>
<%= gravatar_for user, size: 50 %>
<%= link_to user.name, user %>
</li>
提前致谢!