Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Flash[:注意]如果page.blank?_Ruby On Rails_Notice_Respond To - Fatal编程技术网

Ruby on rails Flash[:注意]如果page.blank?

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的更多

我在我的索引页上有一个搜索表单,它重定向到一个页面,该页面显示了所有状态以及搜索给定的参数。现在,如果页面是空白的,因为搜索参数不适合我的任何状态,我想在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