All threads / Passing ActiveRecord Relation object to params?
Ask A Question


You’re not receiving notifications from this thread.

Passing ActiveRecord Relation object to params?

MH asked in Rails

In my controller code, under :index action, I have this sample code
@obj ='user.source_categories.code as category_code, as category_name,
.joins(:table_1, :table_2)
.group(1, 2)
.reorder(count: :desc)

In the Index view, everything is working as expected, it is showing the data stored in @obj. Now in the Index view, I would like to have a "link_to 'category_code', some_path, remote: true", which would direct me to another action of the same controller via AJAX call but at the same time I would like to pass in the @obj, which is an ActiveRecord relation object as one of the params. I need the @obj to further process data once in the other action, and if possible the @obj needs to be maintained as ActiveRecord relation object type. Is it possible to pass ActiveRecord relation object from one action to another action?

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 66,029+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.