Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
brianlu365 opened this issue Jan 22, 2016 · 1 comment

Comments

@brianlu365
Copy link

  • 3.6.0.pre4
  • Rails 4.2.5
  • Chromium Version 47.0.2526.106
  • MySQL

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
Copy link

aguirrel commented May 3, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants