How to group an array of hash by its value which has key-value pair in Ruby (Rails)?

Advertisements So I have following array of hash: my_array = [ { "date" => "2022-12-01", "pic" => "Jason", "guard" => "Steven", "front_desk" => "Emily" }, { "date" => "2022-12-02", "pic" => "Gilbert", "guard" => "Johnny", "front_desk" => "Bella" }, { "date" => "2022-12-03", "pic" => "Steven", "guard" => "Gilbert", "front_desk" => "Esmeralda" } ] My… Read More How to group an array of hash by its value which has key-value pair in Ruby (Rails)?

Rails 7 ActiveQuery select with EXISTS returns an object

Advertisements Trying to run a query for a resource with an additional, computed value. I.e. Model.where(id: 1) .select( ‘models.*’, ‘EXISTS(SELECT 1 FROM models WHERE models.id IS NOT NULL) AS computed_value’ ) I would expect to receive the object, with an additional boolean field computed_value. Instead, the computed_value is being returned as the first record for… Read More Rails 7 ActiveQuery select with EXISTS returns an object

retrieve current parameter value in Rails controller – Error: Couldn't find Question without an ID

Advertisements Upon clicking delete I want my page to redirect to the current user’s poll. This something like this. questions_controller.rb: def destroy @poll_id = Question.find(param[:poll_id]) @question.destroy respond_to do |format| format.html { redirect_to user_poll_url(current_user.id, @question.poll_id), notice: "Question was successfully destroyed." } format.json { head :no_content } end end The Questions_controller’s content is the same as the… Read More retrieve current parameter value in Rails controller – Error: Couldn't find Question without an ID