I am following Michael Hartl's Rails Tutorial and I am in Chapter 9, Section 3.
I am supposed to get:
But instead, I get:
Or, in plain text:
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
Here is the content of my User Helper:
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
And here is the User Controller:
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
Any help to understand what is going wrong would be appreciated.
Following the advice found in this thread fixed the problem: Wrong number of arguments?
Here is the code that should be in the User Helper: