# users_controller.rb
def create
@user = User.new(name: params[:name],
email: params[:email],
password: params[:password],
password_confirmation: params[:password_confirmation])
if @user.save
# successfully saved
flash[:success] = "Sign up success. WELCOME!" # problem
redirect_to user_path(@user.id)
else
@error_messages = @user.errors.full_messages
flash[:danger] = "Sign up failed."
render 'new'
end
debugger
end
Hi, I'm using Rails 5.2.0, ruby 2.4.1 and working on AWS cloud9 environment. This is the code about controller for sign-up page. As you see, the controller takes the information from HTML form and make a @user variable, and save it when it meets the condition I made in app/models/user.rb. I used debugger to test if there is flash[:success] nicely, and debugger says
(byebug) flash
#<ActionDispatch::Flash::FlashHash:0x007f90180a8fe8 @discard=#<Set: {}>, @flashes={"success"=>"Sign up success. WELCOME!"}, @now=nil>
so I can know there is a flash message.
I want to show a sign up success message on that redirected page. But It doesn't work as I expected.
<!-- This is the page when sign up succeed, using semantic-ui -->
<% flash.each do |key, value| %>
<% if key=='success' %>
<div class="ui positive message">
<i class="close icon"></i>
<div class="header"><%= value %></div>
<p>HALLO</p>
</div>
<% end %>
<% end %>
This code render nothing on the page, What's gone wrong with this code? I've already spent over 3 hours to figure out the solution and also read about similar cases on stackoverflow but it doesn't solved my problem.
Am I missing something?