What if there no records to render in a grid? There are three ways to define what to show in this case:
blank_slate
with a block. This looks like a column definition, but the value
returned by the block is rendred when there are no records.
blank_slate
whithout a block, but with one string argument.
blank_slate
with parameter
partial: "partial_name"
which defines a partial to render.
# encoding: utf-8 class NoRecordsController < ApplicationController def index @tasks_grid = initialize_grid(Task, conditions: ['title = ?', 'a title that does not exist']) @tasks_grid2 = initialize_grid(Task, conditions: ['title = ?', 'a title that does not exist']) @tasks_grid3 = initialize_grid(Task, conditions: ['title = ?', 'a title that does not exist']) end end
<%= grid(@tasks_grid2) do |g|
g.blank_slate content_tag(:div, "No records found", class: 'well')
g.column name: 'ID', attribute: 'id'
g.column name: 'Title', attribute: 'title'
end -%>
.well No records found
<%= grid(@tasks_grid) do |g|
g.blank_slate do
content_tag :div, "No records found", class: 'well'
end
g.column name: 'ID', attribute: 'id'
g.column name: 'Title', attribute: 'title'
end -%>
<%= grid(@tasks_grid3) do |g|
g.blank_slate partial: "empty_grid"
g.column name: 'ID', attribute: 'id'
g.column name: 'Title', attribute: 'title'
end -%>
.well %h2= current_page_title %p What if there no records to render in a grid? There are three ways to define what to show in this case: %ul %li %code blank_slate with a block. This looks like a column definition, but the value returned by the block is rendred when there are no records. %li %code blank_slate whithout a block, but with one string argument. %li %code blank_slate with parameter %code partial: "partial_name" which defines a partial to render. = show_code .example1= render 'grid1' .example2= render 'grid2' .example3= render 'grid3'