dimanche 27 août 2023

Updating Record in a after commit call back will trigger infinite calls again and again?

for example

class Order < ApplicationRecord
  after_commit :update_status

  def update_status
     self.update_attribute(:status, 'completed')  
  end
end

im wondering, how this will be handled in rails?

Is it tirgger again and again?

because in some scenarios, its triggering but in some scenrios its not.

samedi 26 août 2023

ActionView::Template::Error (wrong number of arguments (given 2, expected 1))

I am upgrading from Rails 5.2 to Rails 7. After running the server with rails s when I go to any routes, it gives me Completed 500 Internal Server Error

ActionView::Template::Error (wrong number of arguments (given 2, expected 1)):

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>

<%= stylesheet_link_tag    'eye-candy', media: 'all', 'data-turbolinks-track' => true %>

<%= stylesheet_link_tag    'charts', media: 'all', 'data-turbolinks-track' => true %>

app/views/layouts/application.html.erb:19 app/controllers/application_controller.rb:93:in `track'

I tried removing arguments but stylesheet_link_tag is not even taking a single argument.

vendredi 25 août 2023

Error while installing any specific version of ruby through rvm in mac m1

I am facing an issue while installing any version of ruby through rvm in Mac m1. Globally, I have installed ruby version 3.0.0 but for a project, I needed version 3.0.2 but it gives me the following error, no matter how many different versions I try to install the error is the same:

Error running '__rvm_make -j8',

please read /Users/hammadahmad/.rvm/log/1692909928_ruby-2.7.4/make.log

There has been an error while running the make. Halting the installation.

I have tried reinstalling RVM but still no solution. I even tried to do it when rbenv but it gives me other issues like incompatible environment bootsnap.

I tried everything but nothing worked so I'm tired of this.
I want it to work properly and by properly I want to install any version of ruby with the ruby version manager as it does on any other system, The error it is showing is not encountered to anyone else and if it does then there is no guidance about it.

mercredi 23 août 2023

No unique index found for id

I have faced an error "No unique index found for id" while trying to use Upsert all. But isn't ID a unique index by default? Initially we have created our application in rails 3 and now we have migrated it to rails 6. Is this issue related to the migration?

I have added the below migration and it works fine

def change add_index :order_lists, :id, unique: true, algorithm: :concurrently end

mardi 22 août 2023

Tryin to get Users to log in to Microsoft Active directory on my rails app using Omniauth gem

i keep getting this from the console

Started POST "/auth/microsoft_graph" for ::1 at 2023-08-22 11:57:05 +0100
D, [2023-08-22T11:57:05.241303 #14844] DEBUG -- omniauth: (microsoft_graph) Request phase initiated.

without any further response or action on the console. i am not receiving any tokens and also not being redirected to sign in like I should. I have tried it with omniauth-facebook gem to be sure and it's the same response. I believe I'm missing a step but I don't know what it is

i have installed these gem

gem 'omniauth-oauth2'
gem 'omniauth-microsoft_graph'
gem "omniauth-rails_csrf_protection"

then I created this button to sign in:

<%= button_to "Connect microsoft_graph", "/auth/microsoft_graph", method: :post, class: "mt-4 p-2 btn bg-blue-400 rounded" %>

this is the omniauth.rb located in the initializers folder:

Rails.application.config.middleware.use OmniAuth::Builder do
   provider :microsoft_graph, "a47d3c7d-xxxxxxxx", "YOV8Q~9z~xxxxxxxxxxxx"
end

I also created the route in the route.rb file

get "/auth/microsoft_graph/callback", to: "omniauth_callbacks#microsoft"

finally created the controller file and action and microsoft_account model referencing user

class OmniauthCallbacksController < applicationController
    def microsoft
        Rails.logger.info auth
        # render plain: "success"
        current_user.microsoft_accounts.create(

            name: auth.info.name,
            username: auth.info.name,
            token: auth.credentials.token,
            secret: auth.credentials.secret

        )

        redirect_to root_path, notice: "Successfully connected your account"
    end
 def auth
        request.env['omniauth.auth']
    end

lundi 7 août 2023

"bundle install" CA certificates

I am attempting to create a github pages website, and it requires me to do

bundle install

I have tried this, and this is the error message I'm getting:

Fetching source index from https://rubygems.org/
There is a chance you are experiencing a man-in-the-middle attack, but most likely your system doesn't have the CA certificates needed for verification. For information about OpenSSL certificates, see
https://railsapps.github.com/openssl-certificate-verify-failed.html. To connect without using SSL, edit your Gemfile sources and change 'https' to 'http'

I am wary of using 'http' to solve this issue. I have tried downloading the SSL cert file and have followed this guide, but unfortunately am unable to solve the issue: https://bundler.io/guides/rubygems_tls_ssl_troubleshooting_guide.html

These are the two commands I have run:

sudo cp ~/GlobalSignRootCA_R3.pem /usr/lib/ruby/vendor_ruby/rubygems/ssl_certs/rubygems.org
sudo cp ~/GlobalSignRootCA_R3.pem /usr/lib/ruby/3.0.0/rubygems/ssl_certs

Is there anything else I can do? I've looked at the other StackExchange posts, and it seems like this is an old but resolved issue, so I'm at a loss. I am using a Linux machine. Thank you!

samedi 5 août 2023

Looking for guidance for new learning [closed]

I want to learn programming. what do you think which will be better option to explore for a person who is purely from project management background and have basic understanding of just HTML/CSS/BOOTSTRAP and looking to learn more.

  1. Node JS
  2. Angular
  3. Ruby on rails.

I hope in details roadmap for all stacks will help me to better understand this.