I have a issue with flash message in my application. Actually in my application i have used the devise for users authentication and my application with ruby 1.9.3 and rails 3.2.2.
When an user is login, logout and sign up for new account the devise flash[:notice] is working fine.
In Rails flash[:notice] and flash[:alert] are the default flash messages.
The flash messages are display only once when page reload or when the user negative from one page to other page
The issue is when user is login the devise flash[:notice] is displaying but when i reload the page the flash[:notice] is displaying, but in rails the flash[:notice] will display only once
Actually the issue is when i try to create a new post i have redirect to the show page and i have write helper method for flash message this method i have call from the application layout for displaying the flash messages.
In controller create method
def create
@asset = Asset.new(params[:asset])
@asset.user_id = current_user.id
respond_to do |format|
if @asset.save
format.html { redirect_to @asset, alert: 'Asset was successfully created.' }
format.json { render json: @asset, status: :created, location: @asset }
else
format.html { render action: "new" }
format.json { render json: @asset.errors, status: :unprocessable_entity }
end
end
end
The Helper method for displaying flash messages
FLASH_TYPES = [:error, :warning, :success, :message,:notice,:alert]
def display_flash(type = nil)
html = ""
if type.nil?
FLASH_TYPES.each { |name| html << display_flash(name) }
else
return flash[type].blank? ? "" : "<div class=\"#{type}\"><p>#{flash[type]}</p> </div>"
end
html.html_safe
end
i have call this method form the application layout
= display_flash
I have tried with the flash[:alert], flash[:error],flash[:message] but no message display on the view page and i have tried with gem called flash_message this also displays only the flash[:notice]
Please help me to solution this issue