Hi,

I'm trying to implement a grid control with code in the following
places. no worky.

app/views/controls/_AwesomeGrid.erb
app/views/products/index.html.erb
lib/controls/awesome_grid.rb

-- A partial for the HTML output
<div class="grid">
    <p class="search-box"><form><input type="text" value="<%= search
%>" name="search" id="search"> <input type="submit" value="Search" /></
form></p>
    <p class="pagination">Displaying <%= first %>–<%= last %> of <%=
count %></p>
...

-- Embedded in a view
<h1>Listing products</h1>
<%= AwesomeGrid::grid(Product,
    ['title', 'description'], {
        :actions => ['show', 'edit', 'delete']
    }
) %>

-- a module to take the options prepare the data and send to the
partial.
module AwesomeGrid
  def self.grid(model, columns = [], options = {})
    options = {
      :page_size => 10,
      :actions => ['show'],
      :order_by => columns[0],
      :search_by => columns[0]
    }.merge(options)

    ...

    render :partial => "controls/AwesomeGrid", :locals => {
       :model => model,
       :columns => columns,
       :options => options,
       :search => @search,
       :page => @page,
       :first => @first,
       :last => @last,
       :count => @count,
       :number_of_pages => @number_of_pages
   }

   end
end

--

Is this anywhere close to how something like this should look?
I realise that the controller is normally the place for the heavy
lifting but I am wanting to keep all of the querying, searching,
pagination and UI in one place and not have to handle this in all of
the controllers of the app.

Thanks in advance :)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to