I’m working on an application that requires me to fill a model through several pages.
Hence, I need to validate each portion of attributes presented in each form.
I’ve found a way to do so, but I’m wondering if this seems correct, and if I could improve my code ?
def general
@user = User.new
end
def save_general
session[:user] ||= {}
@user = User.new(params[:user].permit(:first_name))
#Apparently, I need to run this once, to populate the errors array.
@user.valid?
unless @user.errors[:first_name].empty?
render :general, status: :unprocessable_entity
else
session[:user][:first_name] = params[:user][:first_name]
end
end