Freibuis

Joined

280 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in How to upgrade to Rails 7.1 Discussion

looks like sidekiq gem team is aware of this

https://github.com/sidekiq/sidekiq/issues/6054

Posted in How to upgrade to Rails 7.1 Discussion

any anyone else having issues with sidekiq after upgrading from 7.1.0.beta1 -> 7.1.0.rc1

undefined method `broadcast' for ActiveSupport::Logger:Class
=> gems/sidekiq-7.1.4/lib/sidekiq/rails.rb:52:in `block (2 levels) in <class:Rails>'

Posted in How to download multiple files from s3 on fly?

you could use the aws-sdk-s3 gem
and something like this

s3 = Aws::S3::Resource.new
s3.bucket(bucket_name).object(object_key).upload_file(file_path)

I would not store your data in the public folder. if you are running multiple nodes behind a reverse proxy like nginx your client might not be able to get the data

if you upload the file to s3, you could send a signed link to the s3 object with a timed limited access (like 10mins etc)

url = s3.bucket(bucket_name).object(object_key).presigned_url(:get, expires_in: 600)

this will allow the user to download directly off AWS s3 without even needing to use your rails server as a resource.

the other option is to download the aws s3 object to a TempFile then use send_file to send it to the client.. this method hides aws S3 from the client. I generally prefer this method but does add to latency/download speed

Posted in How to work with nested methods correctly

this would only work if the namespace nesting would be perfect

Posted in Normalizes method in ActiveRecord Discussion

I would like to add that you can add multiple attributes to be normalized

normalizes [:phone:, :fax, :mobile], with: -> phone_number { phone_number.gsub(/\D/, '') }

Posted in How to work with nested methods correctly

I am trying to figure out how to pass parent arguments to child arguments of a nested method block

so I would like to do something like

namespace "top" do
  namespace "middle" do
    namespace "bottom" do
    end
  end
end

what I would like to have is to create a @namespaces var that stores each concated with its parent

def namespace(path, &block)
  (@namespaces ||= []) << [parent,path].join('/')
  instance_exec(block) if block_given?
end

I would like the value of @namespaces to be

[
  "top",
  "top/middle",
  "top/middle/bottom"
]

so the issue ... I can not figure out how to get the parent path of the outer method (or pass it to the child block)

any ideas?

Posted in Setup Windows 11 Discussion

also just make sure you are using Ubuntu22.04/WSL2 and higher to unlock systemd.. doing this you will also be able to install gui apps like dbeaver to connect to directly to services inside the WSL container without the need for wsl portforwarding.

any gui's that are apt installed will show up in windows start menu

Recently, I created an identity service using Doorkeeper and Devise. To provide additional functionality for our clients, I utilized a Doorkeeper extension called doorkeeper-openid_connect for our federation service. We also integrated omniauth_openid_connect to enable our users to authenticate through OpenID services such as Microsoft. Additionally, I recommend reviewing the source code for GitLab at https://gitlab.com/gitlab-org/gitlab/ as it offers insight into how the protocol works. Although we did not follow that specific approach, it was informative for us.

Posted in Rails 7 and postgres 15

run

brew install libpq

does this solve your issue. not sure if it is still needed on the newer versions of macos

Posted in How I setup sqlite3 on Ruby on windows

if running ubuntu just add the sqlite dev lib package

sudo apt install libsqlite3-dev

btw systemdis now enabled by default in the Ubuntu Preview application.

Posted in Setup Ubuntu 22.10 Kinetic Kudu Discussion

had too many problems with gem collisions with the same versions of ruby using asdf never has any issues with gem-sets on rvm

might have to retry asdf again.. its been awhile

Posted in How to Refresh the OmniAuth AuthHash Discussion

This is a service that I wrote to decouple from the models into a service. this will only work with OAuth-derived strategies.

just call OmniAuthService.refresh!(user_omniauth_provider_record)

force refresh for tokens that have not expired yet

OmniAuthService.refresh!(user_omniauth_provider_record, force: true)

will return true if refreshed and false if not expired or not refreshed

class OmniAuthService
  attr_reader :provider, :name, :force

  # @param [users-provider-class] provider the users provider record
  def initialize(provider, force: false)
    @provider      = provider
    @name        ||= provider.provider.to_sym
    @force         = force
    @token_options = []
    @refreshed     = false
  end

  delegate :expired?,      to: :provider
  delegate :access_token,  to: :provider
  delegate :refresh_token, to: :provider

  # do not refresh unless expired token
  def refresh
    return unless force || expired?

    refresh_provider_tokens
  end

  def refreshed?
    @refreshed
  end

  class << self
    def refresh!(provider, force: false)
      o = new(provider, force:)
      o.refresh
      o.refreshed?
    end
  end

  private
  def refresh_provider_tokens
    new_token = current_token.refresh!
    return if new_token.blank?

    provider.update(
      access_token:  new_token.token,
      expires_at:    Time.zone.at(new_token.expires_at),
      refresh_token: new_token.refresh_token
    )
    @refreshed = true
  end

  def strategy
    Devise.omniauth_configs[name].strategy_class.new(
      Devise.omniauth_configs[name].strategy.app,
      *Devise.omniauth_configs[name].args
    )
  end

  def current_token
    puts token_options
    OAuth2::AccessToken.new(
      strategy.client,
      access_token,
      **token_options
    )
  end

  def token_options
    options = {}
    options.merge({ refresh_token: }) if refresh_token
  end
end


note the strategy method. no need to use const_get. just call the Devise initialized strategy

Posted in Setup Ubuntu 22.10 Kinetic Kudu Discussion

I would use rvm or rbenv to manage ruby versions on per projects with the standard .ruby-version
rvm is a heavier beast compared to rbenv. if you are not changing ruby version often. us rbenv.. otherwise use rvm

to install rvm

curl -sSL https://get.rvm.io | bash

to install a ruby version

rvm install 3.2.3

@RobertMills, thanks.. I took a look at Okta and found it just was a pain to work with.. some things wont let you changes.

We ended up using the oidc-client-ts npm module and created a wrapper OauthClient class to do all the work.

Posted in Is Ruby on Rails still relevant in 2023 ?

yes. but.. and there is always a but.
why I still use Rails in 2023

  • I prefer ruby. I use other languages but always come back.
  • team size, team onboarding.
  • stable
  • fast prototyping.

with team size and team and onboarding makes sense. I have taken over a few node express apps over the last 5 years and converted them to rails api's because any time a new member joins it takes them way to long to get started as code is placed where the original app dev thought was good. Rails apps are good for small to medium teams that rotate a lot, this is because they can use the built in standards and tools to find stuff and fix bugs. the issue we have is that it is hard to keep rails devs as they tend to move on because rails devs tend to get paid pretty well.

Posted in How I setup sqlite3 on Ruby on windows

If you are using Windows use chocolatey to install your sqlite package and dev libraries

choco install sqlite

personally do your ruby/rails work under WSL2 if you want a fun time under windows. since WSL2 now supports systemd you will be able to do 100% the same as you would as a full ubuntu instance

use this guide to get WSL2 running
https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-11-with-gui-support#1-overview

I have a lot of experience running rails on windows...

since windows subsystem for Linux has been out most windows rails devs have moved to wsl as its a better platform form for rails development with the benefit of not having to work out the windows`isms trying to get ruby to work and compile gems correctly

I personally haven't done any rails development on windows for about 3 years since WSL is out.
now that WSL2 supports systemd you will be able to run services pretty close to a native linux experience.

Follow this guide to get WSL2 up and running

https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-11-with-gui-support#1-overview

once you are up and running you will need to get ruby, postgres, and other libraries

# install gpg keys
gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
# install rvm
curl -sSL https://get.rvm.io | bash
# install ruby 3.2.1
# rvm will handle most of the ubuntu packages for you
rvm install 3.2.1

# install the postgres dev library so rails gem install will work
sudo apt install  libpq-dev -y

# install the rails gem (latest version)
gem install rails
  • optional stuff # redis
sudo apt install redis-server

start postgres and redis via an alias

add the following to your ~/.bashrc file

alias dev-start='sudo systemctl start postgresql && sudo systemctl start redis-server'

I personally do not have postgres or redis-server running as start on boot because its a waste of laptop battery until I need it
when you want to run just run dev-start to have both services to run.

now back to postgres. Since this is on WSL you will have access to postgres unix socket. but your local wsl user will probably not have access to it.
you will have 2 options to fix this up.

  • add your local wsl user as a postgres user and give it super user access to postgres
  • lower permission of postgres to allow unix socket access for your user with out any password

if you want to use postgres unix socket you have to remove the :host from the database.yml file . removing the :host tells the pg gem to use the unix socket instead

Pretty much as the title says.. I am looking for a javascript library that can authenticate against Doorkeeper.
We currently have a really old in-house authentication process and migrating to build a brand new federation Idp system that is built around devise/doorkeeper.

all our front ends spa's need to migrate to use doorkeeper/openid using PKCE. the issue is
we have tried the following libraries to limited success
@azure/msal-browser can't use this because the authority URL has to be https so cant be used in development without hassle.
@auth0/auth0-spa-js works against auth0 but its a pain to get it to work against doorkeeper as they uses no standard oauth standard routes creating custom routes in rails alsmost works.

any one know of any great libraries that you use that work really well against doorkeeper using PKCE auth code flow?

I used to use this method object_class: OpenStruct but when you use this pattern you cant

  • transform inside the document it has pointers/links to break out into another object type
  • Chain different secondary api calls for any links/pointers

also

  • OpenStruct has terrible performance and rubocop will complain about this.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.