All threads / Passing ActiveRecord Relation object to params?

Ask A Question

Notifications

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 = UserSource.select('user.source_categories.code as category_code,
user.source_categories.name as category_name,
count(*)')
.merge(@sourced_user)
.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 53,406+ 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.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.