I managed to get it working by:

changing the name of the partial _awesome_grid.erb

-- app/views/products/index.html.erb
render :partial => "controls/awesome_grid",
  :locals => Controls::AwesomeGrid::get_data(
  Product,
  params,
  ['title', 'description'],
  {:actions => ['show', 'edit', 'delete']}
)

-- lib/controls/awesome_grid.rb
module Controls
  module AwesomeGrid
    def self.get_data(model, params, columns = [], options = {})
      return {
        ...
      }
    end
  end
end

Does this seem like an appropriate use of these files or would you
arrange them differently?

Thanks,

On Jul 20, 4:21 pm, markbrown4 <[email protected]> wrote:
> 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