mercredi 6 décembre 2023

Filtering Users with Associated Records by Specific Date in Rails

I'm facing a challenge in a Ruby on Rails application where I need to filter users along with their associated records (Program and Learning), based on a specific date range, but only include those associated records that fall within the given date range.

Models I have the following models:


class User < ApplicationRecord
  has_many :programs
  has_many :learnings
end

class Program < ApplicationRecord
  belongs_to :user
end

class Learning < ApplicationRecord
  belongs_to :user
end

Data Example Consider this data scenario:

User1 has: Program with created_at: Yesterday Learning with created_at: Today User2 has: Program with created_at: Today Learning with created_at: Yesterday

For instance, if I filter for Date.yesterday, I want to get:

User1 with only the Program from yesterday. User2 with only the Learning from yesterday.

Current Approach I've tried various approaches using ActiveRecord queries with joins, where, and eager_load, but I'm either getting users with all their associated records (regardless of the date) or facing issues with structurally incompatible queries.

Can someone suggest a Rails way to achieve this filtering effectively, ensuring that the result is an ActiveRecord::Relation object?

Requirement Given a start and finish date (for example, Date.yesterday), I need to fetch users with their Program and Learning records that were created within this date range. However, the catch is that for a user, I only want to include the Program and Learning records that fall within the specified date range.

I've tried several methods, but none have given me the desired outcome:

  1. Using joins and where: I attempted to use joins with where conditions to filter records. However, this approach either returns users with all their associated records (ignoring the date criteria) or leads to structurally incompatible queries due to the use of or.
Copy code
User.joins(:program, :learnings)
    .where(program: { created_at: start_date..finish_date })
    .or(User.joins(:program, :learnings)
        .where(learnings: { created_at: start_date..finish_date }))

OR

User.joins("LEFT JOIN programs ON programs.user_id = users.id AND programs.created_at BETWEEN '#{start_date}' AND '#{finish_date}'").joins("LEFT JOIN learnings ON learnings.user_id = users.id AND learnings.created_at BETWEEN '#{start_date}' AND '#{finish_date}'")
  1. Subqueries with where: I also experimented with subqueries inside where, but it didn't filter the associated records based on the date criteria.
User.where(id: Program.select(:user_id).where(created_at: start_date..finish_date))
    .or(User.where(id: Learning.select(:user_id).where(created_at: start_date..finish_date)))

mardi 5 décembre 2023

How to handle the params for accepts_nested_attributes_for for has_many association containing a lot of fields on both associated table

I have user model which has has_many association with building model. Initially I was creating the user and the building seperately by using user.create and user.buildings.create because there were some field in the table such that if that field is true then only it create the building and in building also there were condition that if a conditional field in building will be true then more field data will be added to the building. Everything was running smooth till a user create a single building. But when a user started to create more building it bursts the code. Below is the code of users_controller

def create
      role = Role.find_by(id: params[:user][:role_id])
      if role.nil?
        render json: { error: 'invalid role' }, status: :unprocessable_entity
      else
        user = User.new(user_params)
        user.role_id = role.id
        ActiveRecord::Base.transaction do
          if user.save
            # If the user is a technician, handle equipment_params
            if role.name.downcase == 'technician'
              equipment_ids = params[:user][:equipment_id]
              handle_technician_params(user, equipment_ids)
            end
            # If the user is a customer, handle customer_params
            if role.name.downcase == 'customer'
              handle_customer_params(user)
            end
            # Generate a new authentication token for the user
            token, refresh_token = generate_tokens(user.id)
            render json: {  message: 'User created successfully', authentication_token: token, user: user, meta: {photos: UserSerializer.new(user) }}, status: :ok
          else
            render json: { errors: user.errors.full_messages }, status: :unprocessable_entity
          end
        end
      end
    end
def handle_customer_params(user)
      if user_params[:is_customer_direct_point_of_contact] == 'true'
        handle_building_params(user)
      else
        handle_service_params(user)
      end
    end

    def handle_building_params(user)
      building_params = params.require(:building).permit(:service_address_line1, :service_address_line2, :service_zip_code, service_images: [])
      building = user.buildings.create(building_params)
    end
    def handle_service_params(user)
      service_params = params.require(:building).permit(:service_address_line1, :service_address_line2, :service_zip_code, :name, :phone_number, :email, :tax_id, service_images: [])
      building = user.buildings.create(service_params)
    end

I tried to change it to use accepts_nested_attributes_for for direct creating the user and building but did'nt understand how to do that. Is there any also other way to do that?

lundi 4 décembre 2023

Issue when Rounding Decimal values

I am building a test billing application, built in rub on rails, Jquery and Postgres DB (using decimal columns)

This is the below way I am storing values, but I think that is not the way it should save the values

Product 1: 57.5

Charge: 1.7249999999999999

S-Tax: 0.13799999999999998

C-Tax: 4.6

Total: 63.97

Here, I am not rounding any values other than Total when submitting the form; without rounding the Total will be 63.963. So, doing this rounding only for Total and not for others creates issues. For some countries I need to use the precision 2, and others 3

Moreover, I would like to know if this is the correct way to store these values in DB.

Is there any rule like doing the rounding for each column (Charge, S-Tax, C-Tax, and Total)? or any rules for the precision & scale? OR should we convert this to integer?

If we go for integer, should we round it and convert to integer?

What would be the correct data we should store when we submit it? It would be great if someone could suggest, as this has been haunting for some time.

vendredi 1 décembre 2023

Map an activerecord array to avoid that two item with the same attribute are in a sequential position

I have an issue to solve.

I have an array of elements, and on each element I can call the method 'content.sponsored?' that return me true or false.

The items that return true are 2/3 every 20 elements and they are always in the first position.

I need to map this array to avoid consecutive 'true'.

For example

contents = [
  { id: 1, sponsored: true },
  { id: 2, sponsored: true },
  { id: 3, sponsored: false },
  { id: 4, sponsored: false },
  { id: 5, sponsored: false },
  { id: 6, sponsored: false }...
]

I need

contents = [
  { id: 1, sponsored: true },
  { id: 2, sponsored: false },
  { id: 3, sponsored: true },
  { id: 4, sponsored: false },
  { id: 5, sponsored: false },
  { id: 6, sponsored: false }...
]

Which is the most efficient way to map these elements?

jeudi 16 novembre 2023

Devise Registration Ruby on Rails - Migration Error: Duplicate column name

I'm encountering an issue while running a Rails migration that adds Devise to my Users table. The error message points to a duplicate column name, specifically "email." The migration file causing the problem is located at /Users/jaydenthelwell/pye-candles/pye-candles/db/migrate/20231115201715_add_devise_to_users.rb.

Here is the error:

`➜ pye-candles git:(master) ✗ rails db:migrate == 20231115201715 AddDeviseToUsers: migrating ================================= -- change_table(:users) rails aborted! StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: email /Users/jaydenthelwell/pye-candles/pye-candles/db/migrate/20231115201715_add_devise_to_users.rb:7:in block in up' /Users/jaydenthelwell/pye-candles/pye-candles/db/migrate/20231115201715_add_devise_to_users.rb:5:in up'

Caused by: ActiveRecord::StatementInvalid: SQLite3::SQLException: duplicate column name: email /Users/jaydenthelwell/pye-candles/pye-candles/db/migrate/20231115201715_add_devise_to_users.rb:7:in block in up' /Users/jaydenthelwell/pye-candles/pye-candles/db/migrate/20231115201715_add_devise_to_users.rb:5:in up'

Caused by: SQLite3::SQLException: duplicate column name: email /Users/jaydenthelwell/pye-candles/pye-candles/db/migrate/20231115201715_add_devise_to_users.rb:7:in block in up' /Users/jaydenthelwell/pye-candles/pye-candles/db/migrate/20231115201715_add_devise_to_users.rb:5:in up' Tasks: TOP => db:migrate (See full trace by running task with --trace) ➜ pye-candles git:(master) ✗ `

Here's the relevant the migration file:

`# frozen_string_literal: true

class AddDeviseToUsers < ActiveRecord::Migration[7.0] def self.up change_table :users do |t| ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: ""

  ## Recoverable
  t.string   :reset_password_token
  t.datetime :reset_password_sent_at

  ## Rememberable
  t.datetime :remember_created_at

  ## Trackable
  # t.integer  :sign_in_count, default: 0, null: false
  # t.datetime :current_sign_in_at
  # t.datetime :last_sign_in_at
  # t.string   :current_sign_in_ip
  # t.string   :last_sign_in_ip

  ## Confirmable
  # t.string   :confirmation_token
  # t.datetime :confirmed_at
  # t.datetime :confirmation_sent_at
  # t.string   :unconfirmed_email # Only if using reconfirmable

  ## Lockable
  # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  # Uncomment below if timestamps were not included in your original model.
  # t.timestamps null: false
end

add_index :users, :email,                unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token,   unique: true
# add_index :users, :unlock_token,         unique: true

end

def self.down # By default, we don't want to make any assumption about how to roll back a migration when your # model already existed. Please edit below which fields you would like to remove in this migration. raise ActiveRecord::IrreversibleMigration end end

`

I deleted the User migration file as I thought this was causing the issue, the users table also has "email" but the problem persists.

lundi 13 novembre 2023

how to send data to sidekiq queue from ruby app

im new with sideqik and i want to test it for verify that sideqik receive data from a very simple ruby app. exist one method to send data easily?

This is my ruby app:

require "redis"
redis =Redis.new(host: "127.0.0.1", port: 6379)
redis.set("mykey", "hello world!")
redis.post("mykey")

i tried with this script, the connection with sideqik works but when i accessed in its webUI i cant see data. Thank you for help.

Overriding object_changes on paper trails to store name corresponding to change in IDs

For associations, I am assigning IDs from different model to my model and therefore IDs are being changed. Papertrail tracks those changes, and this is the state of my object_changes:

{
  "updated_at": [
    "2023-11-13T08:54:26.346Z",
    "2023-11-13T08:56:06.961Z"
  ],
  "paying_id": [
    "ID1",
    "ID1 new"
  ],
  "company_ids": [
    [
      "ID1",
      "ID2",
      "ID3",
      "ID4"
    ],
    [
      "ID1 new",
      "ID2 new",
      "ID3 new"
    ]
  ]
}

However, in my view for the audit logs, I do not want to display the IDs, but display the names corresponding to those IDs. Right now, I am using if loops to query the names and send to the view. But there must be a better way than this. The docs is also against overriding object_changes, but if object_changes is not overriden, then how?

What is the correct way to do this?

vendredi 3 novembre 2023

Why do I get NoMethodError: undefined method `rescue' for #

Ruby's Concurrent::Future was not catching the exceptions. So I copied the code from an article to add a rescue block. But now I got the error:

Caused by NoMethodError: undefined method `rescue' for #Concurrent::Future:0x0000000124764268

Here is the code:

executed_future = Concurrent::Future.execute do
            url = "#{endpoint}#{datum[:hierarchy_id]}#{valuation_date}"
            raise StandardError.new("Testing error!") # To test

            [...]
          end.rescue do | exception | # Adding this, will throw the error
            @exceptions << exception
            binding.pry # No activated
          end

What am I missing?

I expect to rescue exceptions in the Concurrent::Future block. Just like the article does.

mardi 31 octobre 2023

undefined method `to_model' for #

<%= form_with(model:[@single_room, @message] , remote: true, class: "d-flex" ) do |f| %> <%= f.text_field :body, id: 'chat-text', class: "form-control ", autocomplete: 'off' %> <%= f.submit data: { disable_with: false }, class: "btn btn-primary" %> <% end %>

why it is coming like this

lundi 30 octobre 2023

Mailgun Showing Variable Names as it is Ruby on Rails

I have a template field in my object in which i store the whole email template and store it like below "<p><span style=\"font-family: -apple-system, system-ui, &quot;Segoe UI&quot;, Roboto, Oxygen-Sans, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;\">%recipient.email%<b><br></b></span><b>&nbsp;<br>&nbsp;</b><span style=\"font-family: -apple-system, system-ui, &quot;Segoe UI&quot;, Roboto, Oxygen-Sans, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;\">%recipient.tier_name%</span></p>" in this %recipient.email% is my variable and it will changed by mailgun automatically but the issue is sometimes it does not reflect and appear as it is in the email with out changing its actaul value

example: If recipient.email = test@gmail.com but in email it is showing %recipient.email% instead of test@gmail.com

I want to apply the variable values instead of its variable names. example: If recipient.email = test@gmail.com but in email it is showing %recipient.email% instead of test@gmail.com

def self.send_emails(subject:, html:, to_emails:, recipient_variables: {}, force_send: false, sender_email)
payload = {
  from: sender_name(sender_email),
  subject:,
  html:,
  'recipient-variables': recipient_variables.to_json,
  'o:tag': [subject, tag]
}
esponse = RestClient.post(mailgun_api_url(sender_email), payload)

end

vendredi 27 octobre 2023

Error (Could not find the inverse association for profile_image_attachment (:record in ActiveStorage::Attachment)):

In my model/active_storage/attachment.rb file i had used this code

class ActiveStorage::Attachment < ApplicationRecord belongs_to :blob, class_name: "ActiveStorage::Blob" def self.ransackable_attributes(auth_object = nil) ["blob_id", "created_at", "id", "name", "record_id", "record_type"] end end "When creating Active Admin with Active Storage, I encountered a search error. To address this, I used defined the ransackable method in my model." in my model/user.rb i had used has_one_attached :profile_image when i open this link http://127.0.0.1:3000/users/1 it show this error unknown keywords: :class_name, :as, :inverse_of and when i open this link http://127.0.0.1:3000/admin it open successfullyenter image description here

i had used inverse of in my model/user.rb file , but it did't work i had go through all my schema file it generate activestorage of correctlly.

jeudi 26 octobre 2023

ActiveRecord::InverseOfAssociationNotFoundError in rails 7

Hii in my rails application when I going to open the profile page the following error comes My ruby version is "3.2.2" and my rails version is "7.0.8"

ActiveRecord::InverseOfAssociationNotFoundError in Users#show

Showing /home/nitish/Documents/Bestristey/app/views/users/_user_profile_image.html.erb where line #3 raised:

ActionView::Template::Error (Could not find the inverse association for profile_image_attachment (:record in ActiveStorage::Attachment)):

        1: <div id="profile_image">
        2:     <div>
        3:         <% if user.profile_image.attached? %>
        4:         <%= image_tag(user.profile_image, class: "d-block ui-w-80 " ) %>
        5:         <% else %>
        6:         <img src ="/assets/dummy profile.jpg" alt class="d-block ui-w-80 rounded-circle">

This is the code of my user model:-

class User < ApplicationRecord

      after_create :after_confirmation
  
      devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :trackable
            
      validates :username, presence: true, uniqueness: true

      has_one_attached :profile_image

      attr_accessor :login
  
      def login
        @login || self.username || self.email
      end
     end


And this is the code from my models/active_storage/attachment.rb file:-

`
class ActiveStorage::Attachment < ApplicationRecord

        belongs_to :blob, class_name: "ActiveStorage::Blob", inverse_of: :attachment

    
  
        def self.ransackable_attributes(auth_object = nil)
          ["blob_id", "created_at", "id", "name", "record_id", "record_type"]
        end
  
      end

I have tried of using :inverse_of in the users model has_one_attached association but then it gives argument error. I also tried some other stuffs also but still no any progress.

mercredi 25 octobre 2023

dyld[4255]: missing symbol on Apple M2

I am running ruby on rails project on my apple M2. Ruby version is 2.5.5. I have done setup using rosetta. After installing all the dependencies when i try to run the console i.e. rake c. I get this error

dyld[4255]: missing symbol called [1] 4255 abort rake c

I have tried removing the old ruby and starting this process from scratch. Have also installed brew using rosetta.

Does anyone know how to solve this?

lundi 23 octobre 2023

Calling a Static Method from a Controller and Updating instance of that class - Getting undefined method for AR::Association::HasOneAssociation

My Question:

What should the correct structure be? I have tried redesign this several times but keep getting tight-coupling issues.

Relevant Info:

I am writing a new endpoint for some third party software. It will receive a payload that I am then passing into a static method of my Subscription class. From there I want to do a look-up of the payload related subscription, establish an instance of it, then perform an update based off the rest of my information on my class. I am running into an error that is saying the following: undefined method update for ActiveRecording::Association::HasOneAssociation

EndPointController:

class Api::V2::EndpointController < Api::V5::BaseController
    def connect
        data = decode(request.body.read)
        Subscription.static_method(data)
    end
end

Subscription Model:

class Subscription < ActiveRecord::Base

    def self.static_method(data)
        @subscription = Subscription.find_by_id(data.subscription_id)
        @subscription.update(data)
    end
end

Subscription Controller:

class SubscriptionsController < ApplicationController
    def update
        #execute update
    end
end

how to debug gitlab-ce docker container?

My environment: osx14.0 rubymine gitlab-ce 16.4

I want to debug gitlab-ce remotelly with local rubymine on my mac. I expose 3000 in the docker container, but rubymine cannot debug it on 3000 port directly. I am more familiar to Java and PHP, but new to ruby thanks!

I tried to use rubymine connect to 3000 port on the docker container, but I failed

jeudi 19 octobre 2023

Update Database in Ruby on Rails version 7.11

Hello community I am new to ruby on rails, I have a problem with updating the database, when I try to update a record, all records are updated

this is my article_controller this is my router

I was reviewing the documentation and I saw that I do it similarly, I have searched for information on the internet and I can't find a solution

I want to update only one record by passing the id

mardi 3 octobre 2023

How to authenticate and access the Gmail API in Ruby without using OOB

How do I connect to the api without using oob since it is obsolete, I have been searching and I can't find any example. Alguna ayuda

These are the methods for OOB but I don't need to use them as they are deprecated.

type here
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'google/apis/gmail_v1'

# Constants for authentication
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze
APPLICATION_NAME = 'Your Gmail Application'
CLIENT_SECRETS_PATH = 'path/to/client_secrets.json'.freeze
CREDENTIALS_PATH = 'path/to/credentials.yaml'.freeze
SCOPE = Google::Apis::GmailV1::AUTH_SCOPE

# Configure authentication
client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)
authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE)
credentials = authorizer.get_credentials('user_id', token_store)

Step 2: Credential Verification
In this step, we'll check if we already have stored credentials or if we need user authentication.

# Check if credentials exist or if user authentication is needed
if credentials.nil?
  url = authorizer.get_authorization_url(base_url: OOB_URI)
  puts 'Open the following URL in your browser and enter the authorization code:'
  puts url
  code = gets
  credentials = authorizer.get_and_store_credentials_from_code(
    user_id: 'user_id', code: code, base_url: OOB_URI, token_store: token_store
  )
end

jeudi 21 septembre 2023

i want to see server log file from browser in rails app button click

i have a make a deployment app , by clicking deployment button it deployed, now i want to see the log file like terminal show in browser

i try to read the log file using file read but when i start to read my application stop with this

Rendering deployments/show_log.html.erb within layouts/application
/home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/core_ext/string/output_safety.rb:350: [BUG] Segmentation fault at 0x00007f46a87f1000
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0123 p:---- s:0827 e:000826 CFUNC  :escapeHTML
c:0122 p:0036 s:0822 e:000821 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/core_ext/string/output_safety.rb:350
c:0121 p:0012 s:0814 e:000812 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/core_ext/string/output_safety.rb:216
c:0120 p:0016 s:0808 e:000807 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/buffers.rb:29
c:0119 p:0022 s:0803 e:000802 METHOD /home/syftet/development/trusteeze-saas/app/views/deployments/show_log.html.erb:2 [FINISH]
c:0118 p:---- s:0797 e:000796 CFUNC  :public_send
c:0117 p:0042 s:0790 e:000789 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/base.rb:244
c:0116 p:0025 s:0776 e:000775 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/template.rb:157
c:0115 p:0034 s:0773 e:000772 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:208
c:0114 p:0024 s:0767 e:000766 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/template.rb:361
c:0113 p:0021 s:0762 e:000761 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/template.rb:155
c:0112 p:0013 s:0751 e:000750 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:65
c:0111 p:0010 s:0748 e:000747 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:206
c:0110 p:0022 s:0745 e:000744 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications/instrumenter.rb:24
c:0109 p:0023 s:0737 e:000736 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:206
c:0108 p:0033 s:0731 e:000730 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:60
c:0107 p:0011 s:0727 e:000724 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:75
c:0106 p:0010 s:0722 e:000721 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:206
c:0105 p:0022 s:0719 e:000718 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications/instrumenter.rb:24
c:0104 p:0023 s:0711 e:000710 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/notifications.rb:206
c:0103 p:0050 s:0705 e:000704 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:74
c:0102 p:0012 s:0695 e:000694 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:59
c:0101 p:0048 s:0687 e:000686 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/template_renderer.rb:11
c:0100 p:0020 s:0680 e:000679 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/renderer.rb:61
c:0099 p:0023 s:0674 e:000673 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/renderer/renderer.rb:29
c:0098 p:0009 s:0668 e:000667 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/rendering.rb:117
c:0097 p:0089 s:0664 e:000663 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/base.rb:270
c:0096 p:0051 s:0656 e:000655 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/rendering.rb:116
c:0095 p:0044 s:0646 e:000645 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/streaming.rb:216
c:0094 p:0015 s:0641 e:000640 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionview-7.0.5/lib/action_view/rendering.rb:103
c:0093 p:0010 s:0636 e:000635 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/rendering.rb:158
c:0092 p:0015 s:0631 e:000630 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/renderers.rb:141
c:0091 p:0018 s:0626 e:000625 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/abstract_controller/rendering.rb:27
c:0090 p:0033 s:0618 e:000617 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/rendering.rb:139
c:0089 p:0010 s:0613 e:000612 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/instrumentation.rb:22
c:0088 p:0028 s:0610 e:000609 METHOD /home/syftet/.rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/benchmark.rb:308
c:0087 p:0009 s:0605 e:000603 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/core_ext/benchmark.rb:14
c:0086 p:0013 s:0599 e:000598 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/instrumentation.rb:22
c:0085 p:0002 s:0596 e:000595 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/instrumentation.rb:91
c:0084 p:0066 s:0592 e:000591 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/activerecord-7.0.5/lib/active_record/railties/controller_runtime.rb:34
c:0083 p:0008 s:0585 e:000583 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/instrumentation.rb:21
c:0082 p:0021 s:0578 e:000577 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/implicit_render.rb:35
c:0081 p:0020 s:0573 e:000572 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/basic_implicit_render.rb:7
c:0080 p:0011 s:0566 e:000565 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/abstract_controller/base.rb:215
c:0079 p:0022 s:0560 e:000559 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/action_controller/metal/rendering.rb:165
c:0078 p:0009 s:0555 e:000554 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actionpack-7.0.5/lib/abstract_controller/callbacks.rb:234
c:0077 p:0048 s:0552 E:002550 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/activesupport-7.0.5/lib/active_support/callbacks.rb:118
c:0076 p:0013 s:0542 E:002590 METHOD /home/syftet/.rvm/gems/ruby-3.0.0/gems/actiontext-7.0.5/lib/action_text/rendering.rb:20
c:0075 p:0021 s:0536 E:0025d0 BLOCK  /home/syftet/.rvm/gems/ruby-3.0.0/gems/actiontext-7.0.5/lib/action_text/engine.rb:69 [FINISH]
c:0074 p:---- s:0531 e:000530 CFUNC  :instance_exec

mardi 19 septembre 2023

Insert many json file inside one document in mongoDB

i have a question: but how can i insert many json files inside one document collection? I have a ruby script connected with mongoDB which generate json files for each ID product. In mongo i should want a structure like this:

Id(document's name) : {

many json for same ID

} 

how can i get this structure in ruby?

DB's name is "test_db" and collection's name is "test_coll"

mardi 12 septembre 2023

URI Error with RUBY when trying to run an application

so for some reason my ruby encounter this error when I try to create a new application on Windows 10:

rails aborted! URI::InvalidURIError: bad URI(is not URI?): C:\Ruby\bin;C:\sqlite; C:/Users/Lies/demo42/Rakefile:6:in <main>' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' bin/rails:4:in <main>' (See full trace by running task with --trace) rails turbo:install stimulus:install rails aborted! URI::InvalidURIError: bad URI(is not URI?): C:\Ruby\bin;C:\sqlite; C:/Users/Lies/demo42/Rakefile:6:in <main>' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' <internal:C:/Ruby/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' bin/rails:4:in <main>' (See full trace by running task with --trace)

I've searched everywhere on Google and so far I've try reinstalling twice, changing the path varible to C:\ruby and adding it to path and DATABASE variable.

My ruby, rails is on the latest version.

So far running "rails new demo --minimal" is the only one that work in helping me creating the application but when I try to run the server it show this: localhost:3000 output

Has anyone encountered this and figure out how to fix? I asked my professor, and it also picked his brain trying to figure out.

Thank you!