Rahul kumar
Rahul kumar

Reputation: 13

Render and/or redirect were called multiple times in this action. You may only call render OR redirect, and at most once per action issue

When I am changing the page using pagination button or using the scrobble bar in the kanban board card getting DoubleRenderError in Ruby on Rails occurs when I attempt to both render and redirect in the same action of a controller. As the error suggests, you can only call either render or redirect_to once per action

  def index
    session[:current_page] = "all_request"
    default_per_page = 15
    @per_page = params[:per_page] || session[:per_page] || default_per_page
    session[:per_page] = @per_page
    @q = ClientRequest.includes(:resource_infos, :developers).page(params[:page]).per(@per_page).ransack(params[:q])
    if (params[:q] && @filter_per_page_value = params[:q][:per_page_eq]) != nil
      @per_page = @filter_per_page_value
      @q = ClientRequest.includes(:resource_infos, :developers).page(params[:page]).per(@per_page).ransack(params[:q])
    end
    @client_requests = @q.result

    kanban_view_details
    render_partials
  end



  def kanban_view_details
    kanban_column_data = KanbanColumn.in_order_of(:name, KanbanViewHelper::KANBAN_COLUMN_ORDER.keys)
    @grouped_kanban_columns = {}
    kanban_column_data.each do |kanban_column|
      custom_sorting_expression, sorted_records = generate_sorted_records(kanban_column)
      pagy, client_requests = pagy_countless(sorted_records, items: 6, page_param: kanban_column.name)
      @grouped_kanban_columns[kanban_column] = [pagy, client_requests]
    end
    load_cache
    @pagy, @kanban_columns = pagy_countless(kanban_column_data, items: 9)
  
    if params[:page]
      render "scrollable_list"
    elsif params[:load]
      render partial: "kanban_views/common_view/common_kanban_page"
    end
  end


  def render_partials
    kanban_view_details
    partial_name = params[:name]
    if partial_name == "classic_view"
      render partial: "classic_views/classic_view"
    elsif partial_name == "kanban_view"
      load_cache
      render partial: "kanban_views/common_view/common_kanban_page", locals: { client_request_cache: @client_request_cache }
    end
  end

Upvotes: 0

Views: 178

Answers (1)

Christian Martin
Christian Martin

Reputation: 1

I think you are calling render in the kambas and the final render in the index. just change the code to make it to if it render the kambas has a return after to prevent the index return

Upvotes: 0

Related Questions