我的索引页面上有一个搜索表单,该表单重定向到一个页面,该页面显示所有状态以及搜索给出的参数。现在我想在页面为空白时发出一个快速通知,因为搜索参数不适合我的任何状态。任何想法?问候
问问题
94 次
4 回答
1
尝试这个
@search = User.find('status', params[:status])
rediret_to page_path, notice: "Requested status is not available" if @search.present?
于 2013-12-23T11:44:05.910 回答
0
这应该没问题:
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-23T11:39:48.287 回答
0
如果搜索到的对象为零,则将 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
end
于 2013-12-23T11:40:53.500 回答
0
def search_status
@search = User.find_by_status(params[:status])
if !@search.present?
flash[:notice] = 'Requested status not available'
rediret_to '/Index'
end
end
于 2013-12-23T12:09:02.180 回答