我在我的索引页面上有一个搜索表单,该表单重定向到一个页面,该页面显示搜索给定的参数的所有状态。现在,如果页面是空白的,因为搜索参数不适合我的任何状态,我想放一个闪光灯通知。有什么想法吗?问候
发布于 2013-12-23 19:44:06
尝尝这个
@search = User.find('status', params[:status])
rediret_to page_path, notice: "Requested status is not available" if @search.present?发布于 2013-12-23 19:39:48
这应该没问题:
def index
@statuses = Status.scope_to_retreive_statuses
flash.now[:notice] = 'No statuses to display' if @statuses.empty?
end有关flash的更多信息,请点击此处:http://guides.rubyonrails.org/action_controller_overview.html#the-flash。
发布于 2013-12-23 19:40:54
如果搜索到的对象为空,则将flash通知放入else条件中。
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
endhttps://stackoverflow.com/questions/20742723
复制相似问题