I have a large "data" active record object whose info I filter based on what the user clicks on a page, then I display that filtered data to the user. I was wondering where the best place to put the data-filtering logic is. Right now I do the filtering in the rails controller action, so that in the view I only have to say something like
<script>
var filtered_data = <%= raw @filtered_data %>
alert('first piece of data is: '+filtered_data[0])
var filtered_names = <%= raw @filtered_names %>
</script>
and other such vars.
or, I was considering just passing the whole @data like:
<script>
var data = <%= data.to_json.html_safe %>
var filtered_data = **some js logic to filter data var**
var filtered_names = **more js logic to filter for names, maybe using the jquery .map function, etc **
</script>
which way is better for performance? I would think client-side JS is better, but it's probably not client side anymore since it's a .js.erb? Or would having more logic in the js.erb still help a bit?
Thanks for any insight!