narrow-electrician-89982
10/25/2023, 8:49 AMruby
class Avo::ToolsController < Avo::ApplicationController
def stats_fixer
@page_title = "Stats fixer"
add_breadcrumb "Stats fixer"
end
def process_stats_fixer
Parallel.each(User.all) do |user|
user.update_caching_data!
rescue StandardError => e
Rails.logger.error "#{DateTime.now} - Error in fixer_user_stats - #{e}"
end
end
end
ruby
scope :admin do
get "stats_fixer", to: "avo/tools#stats_fixer"
post 'process_stats_fixer', to: 'avo/tools#process_stats_fixer'
end
what's the easiest way of rendering the button to call this action ? I'm getting weird results every timeminiature-optician-85831
10/25/2023, 8:49 AMloud-jewelry-99127
10/25/2023, 8:52 AMnarrow-electrician-89982
10/25/2023, 8:53 AMnarrow-electrician-89982
10/25/2023, 8:53 AMnarrow-electrician-89982
10/25/2023, 8:53 AMnarrow-electrician-89982
10/25/2023, 8:54 AMnarrow-electrician-89982
10/25/2023, 8:54 AMloud-jewelry-99127
10/25/2023, 8:56 AMnarrow-electrician-89982
10/25/2023, 8:58 AMnarrow-electrician-89982
10/25/2023, 8:58 AMnarrow-electrician-89982
10/25/2023, 8:58 AMruby
def stats_fixer
@page_title = "Stats fixer"
add_breadcrumb "Stats fixer"
end
def process_stats_fixer
Parallel.each(User.all) do |user|
user.update_caching_data!
rescue StandardError => e
Rails.logger.error "#{DateTime.now} - Error in fixer_user_stats - #{e}"
end
return redirect_to '/admin/stats_fixer', notice: "Stats fixer done!"
end
ruby
<% c.with_tools do %>
<%= a_link('/admin/process_stats_fixer', icon: 'heroicons/outline/finger-print', style: :primary, is_link: true) do %>
Reset stats
<% end %>
<% end %>
narrow-electrician-89982
10/25/2023, 8:59 AMprocess_stats_fixer
, where I run the code, and then the page redirects with a noticenarrow-electrician-89982
10/25/2023, 8:59 AMloud-jewelry-99127
10/25/2023, 9:01 AMflash[:notice] = "Stats fixer done!"
inside process_stats_fixer
and render stats_fixer
as response would not need the extra request i thinknarrow-electrician-89982
10/25/2023, 9:02 AMpost
it wouldn't need it ( I guess ) ; but since `post`ing will only work with forms, I did it as a get and redirectnarrow-electrician-89982
10/25/2023, 9:02 AMnarrow-electrician-89982
10/25/2023, 9:04 AMloud-jewelry-99127
10/25/2023, 9:08 AMloud-jewelry-99127
10/25/2023, 9:08 AMruby
<%= a_link('/admin/process_stats_fixer', icon: 'heroicons/outline/finger-print', style: :primary, is_link: true, method: :post) do %>
loud-jewelry-99127
10/25/2023, 9:08 AMruby
def process_stats_fixer
Parallel.each(User.all) do |user|
user.update_caching_data!
rescue StandardError => e
Rails.logger.error "#{DateTime.now} - Error in fixer_user_stats - #{e}"
end
flash[:notice] = "Stats fixer done!"
respond_to do |format|
format.turbo_stream do
render partial: "avo/partials/flash_alerts"
end
end
end
narrow-electrician-89982
10/25/2023, 9:09 AMsh
Missing partial avo/partials/_flash_alerts
loud-jewelry-99127
10/25/2023, 9:09 AMloud-jewelry-99127
10/25/2023, 9:09 AMloud-jewelry-99127
10/25/2023, 9:09 AMloud-jewelry-99127
10/25/2023, 9:10 AMnarrow-electrician-89982
10/25/2023, 9:10 AMloud-jewelry-99127
10/25/2023, 9:10 AMloud-jewelry-99127
10/25/2023, 9:10 AMnarrow-electrician-89982
10/25/2023, 9:10 AMnarrow-electrician-89982
10/25/2023, 9:10 AMloud-jewelry-99127
10/25/2023, 9:10 AM2.43
do you intent to upgrade soon?narrow-electrician-89982
10/25/2023, 9:12 AMloud-jewelry-99127
10/25/2023, 9:12 AMloud-jewelry-99127
10/25/2023, 9:12 AMnarrow-electrician-89982
10/25/2023, 9:12 AMnarrow-electrician-89982
10/25/2023, 9:12 AMnarrow-electrician-89982
10/25/2023, 9:12 AMloud-jewelry-99127
10/25/2023, 9:12 AM