Flashing the User

I learned last night the flash variable in Rails. It is a special variable that stores data temporarily.

My group at flatiron school is building an application this week and I was assigned the task to research on how to build a signup/signin functionality. The Rails flash would show the user a welcome message as soon as he/she creates an account for example.

Here is how I added the flash variable to the application. In the layouts/applications.html.erb file I used erb to iterate over the flash.

Screen Shot 2014-01-17 at 9.28.01 AM

Flash[:success] is what I want to show, which is going to be the value of the :success key, thus only.

After tampering with the view, I went to the users_controller.rb file and added the following after I saved a user to database:

def create @user = User.new(params[:user]) if @user.save sign_in @user flash[:success] = "Welcome to Gentle Reminder" redirect_to new_user_goal_path(@user) else render "new" end end


flash[:success] = "Welcome to Gentle Reminder"

is the code that will display the flash message once the user creates an account.

Lo and behold, I flashed my user.
Screen Shot 2014-01-17 at 9.20.06 AM


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s