我關注的邁克爾·哈特爾的Rails的教程,我在第9章,第3節引發ArgumentError在UsersController#指數錯誤的參數數目(2 1)
我應該得到:
但是,相反,我得到:
或者,以純文本格式:
ArgumentError in UsersController#index
wrong number of arguments (2 for 1)
Extracted source (around line #4):
# Returns the Gravatar for the given user.
def gravatar_for(user)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
Rails.root: /Users/TXC/code/microblog
Application Trace | Framework Trace | Full Trace
app/helpers/users_helper.rb:4:in `gravatar_for'
app/views/users/index.html.erb:7:in `block in _app_views_users_index_html_erb___2825860878015368470_70324743747280'
app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb___2825860878015368470_70324743747280'
Request
Parameters:
None
Toggle session dump
這裏是我的用戶助手的內容:
module UsersHelper
# Returns the Gravatar for the given user.
def gravatar_for(user)
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
end
這裏是用戶控制器:
class UsersController < ApplicationController
before_action :logged_in_user, only: [:index, :edit, :update]
before_action :correct_user, only: [:edit, :update]
def index
@users = User.all
end
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
log_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
def edit
end
def update
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
# Before filters
# Confirms a logged-in user.
def logged_in_user
unless logged_in?
store_location
flash[:danger] = "Please log in."
redirect_to login_url
end
end
# Confirms the correct user.
def correct_user
@user = User.find(params[:id])
redirect_to(root_url) unless current_user?(@user)
end
end
任何幫助,瞭解了什麼錯誤,將不勝感激。