I am having a search form on my index page that redirects to a page that shows all statuses with the params given by search. Now I want to put in a flash notice if the page is blank because the search param doesn't fit to any of my statuses. any idea? greetz
Flash[:notice] if page.blank?
167 Views Asked by user3079933 At
4
There are 4 best solutions below
0

Put flash notice in else condition if searched object is nil.
def search_status
@search = User.find_by_status(params[:status])
if @search.present?
// Respective action
else
flash[:notice] = 'Requested status is not available'
rediret_to '/Index'
end
end
0

Try This
@search = User.find('status', params[:status])
rediret_to page_path, notice: "Requested status is not available" if @search.present?
0

def search_status
@search = User.find_by_status(params[:status])
if [email protected]?
flash[:notice] = 'Requested status not available'
rediret_to '/Index'
end
end
This should be ok:
More info about
flash
here: http://guides.rubyonrails.org/action_controller_overview.html#the-flash