Controller:
def store
if params[:name].present? && params[:pass].present? && params[:cpass].present? && params[:role].present?
@name = params[:name].downcase
if CheckEmpName(@name) == 0
render "userexist"
return
end
pass = params[:pass]
cpass = params[:cpass]
if pass != cpass
render "passerror"
return
end
role = params[:role]
@user = Employee.new(name: @name, password: pass, role: role)
@user.save
end
render "success"
end
The above action renders the "success.html.erb" page when all the user inputs are valid. Instead if the username is already registered or both the password and confirm password are not matched then it renders the appropriate error files which is "userexist.html.erb" or "passerror.html.erb".
Problem:
I am able to access @name instance variable in success.html.erb file. But I am not able to access that in both of the error html files. Why it is only accessible in "success" and not in "userexist" and "passerror". Why it is not accessible. And What I need to do to access those variable in both of the error handling html pages ?
userexistorpasserrorare being rendered.