leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 213 forks source link

initialize_grid with ActiveRecord::Relation that contains alias attribute no longer works in 3.6.0.pre4 #271

Open brianlu365 opened 8 years ago

brianlu365 commented 8 years ago

In model I have a query with alias in select

def self.receiving_check
    LineItem.select("*, (line_item.quantity - supplier.stock_change) as remain_quantity").joins( ...
end

It returns a activerecord relation something like this

<LineItem ...., remain_quantity: 100>

but after I initialize_grid in controller and render the attribute in view, I got undefined method error. The same code works with wice_grid 3.4.14

ActionView::Template::Error:
       undefined method `remain_quantity' for #<LineItem:0x007f88c2535d20>

This is how I initialized_grid in controller

@report_grid = initialize_grid(LineItem.receiving_check,
                                     joins: [:assembly_info],
                                     name: 'receiving_check',
                                     per_page: 25,
                                     order: 'creation_time',
                                     order_direction: 'desc',
                                     enable_export_to_csv: true,
                                     csv_file_name: "Receiving_check_#{Time.now.strftime('%Y%m%d')}")

render in view

= grid(@report_grid, show_filters: :when_filtered) do |g|
  - g.column name: t('th.remain_quantity') do |p|
    - p.remain_quantity
aguirrel commented 6 years ago

Hi @brian-vogogo did you find any solution? I have a similiar problem. Thanks!