Ruby on rails Flash[:注意]如果page.blank?
我在我的索引页上有一个搜索表单,它重定向到一个页面,该页面显示了所有状态以及搜索给定的参数。现在,如果页面是空白的,因为搜索参数不适合我的任何状态,我想在flash中添加一个通知。有什么想法吗? 格里茨这应该没问题:Ruby on rails Flash[:注意]如果page.blank?,ruby-on-rails,notice,respond-to,Ruby On Rails,Notice,Respond To,我在我的索引页上有一个搜索表单,它重定向到一个页面,该页面显示了所有状态以及搜索给定的参数。现在,如果页面是空白的,因为搜索参数不适合我的任何状态,我想在flash中添加一个通知。有什么想法吗? 格里茨这应该没问题: def index @statuses = Status.scope_to_retreive_statuses flash.now[:notice] = 'No statuses to display' if @statuses.empty? end 有关flash的更多
def index
@statuses = Status.scope_to_retreive_statuses
flash.now[:notice] = 'No statuses to display' if @statuses.empty?
end
有关flash
的更多信息,请点击此处:
如果搜索的对象为零,则将flash notice置于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
试试这个
@search = User.find('status', params[:status])
rediret_to page_path, notice: "Requested status is not available" if @search.present?
def search_status
@search = User.find_by_status(params[:status])
if !@search.present?
flash[:notice] = 'Requested status not available'
rediret_to '/Index'
end
end