新規登録実装 引数エラー wrong number of arguments (given 0, expected 1)
新規登録実装中に引数に関するエラーが出ました。
何の引数を追加すれば良いのか分からないので教えて頂きたいです。
ArgumentError in UsersController#create
wrong number of arguments (given 0, expected 1)
user.controller.rb
class UsersController < ApplicationController
before_action :authenticate_user, {only: [:index, :show, :edit, :update]}
before_action :forbid_login_user, {only: [:new, :create, :login_form, :login]}
before_action :ensure_correct_user, {only: [:edit, :update]}
def index
@users = User.all
end
def show
@user = User.find_by(id: params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(
name: params[:name],
email: params[:email],
image_name: "fashion-985556_1920.jpg",
password: params[:password]
)
if @user.save ←ここがエラーになりました。
session[:user_id] = @user.id
flash[:notice] = "ユーザー登録が完了しました"
redirect_to("/users/#{@user.id}")
else
render("users/new")
end
end
def edit
@user = User.find_by(id: params[:id])
end
def update
@user = User.find_by(id: params[:id])
@user.name = params[:name]
@user.email = params[:email]
if params[:image]
@user.image_name = "#{@user.id}.jpg"
image = params[:image]
File.binwrite("public/user_images/#{@user.image_name}", image.read)
end
if @user.save
flash[:notice] = "ユーザー情報を編集しました"
redirect_to("/users/#{@user.id}")
else
render("users/edit")
end
end
def login_from
end
def login
@user = User.find_by(email: params[:email])
if @user && @user.authenticate(params[:password])
session[:user_id] = @user.id
flash[:notice] = "ログインしました"
redirect_to("/posts/index")
else
@error_message = "メールアドレスまたはパスワードが間違っています"
@email = params[:email]
@password = params[:password]
render("users/login_form")
end
end
def auth_failure
@user = User.new
render("users/login_form")
end
def logout
session[:user_id] = nil
flash[:notice] = "ログアウトしました"
redirect_to("/login")
end
def ensure_correct_user
if @current_user.id != params[:id].to_i
flash[:notice] = "権限がありません"
redirect_to("/posts/index")
end
end
end
model/user.rb
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_secure_password
validates :name, {presence: true}
validates :email, {presence: true, uniqueness: true}
has_many :comments
def posts
return Post.where(user_id: self.id)
end
end
0