Category "ruby"

How to reduce the number of tracking records when saving on keystroke?

When saving changes to a model in rails, two popular gems to track changes are paper_trail and audited. These gems create records that contain versioning inform

How to mock module static method in ruby rspec?

I am trying to write some rspec tests and I want to mock a static method from a module. The setup is like this: module MyModule def self.my_method 'end' en

Rails ActiveStorage Variants url

I'm trying to create an api to get a model's original image and other variants. Right now I'm not storing attachments on external storage, but I plan to save th

Is there an equivalent tool like ruby-prof for node.js?

I want to profile a Jest test, but I only want to see the behavior for some specific methods. In ruby, I can do that with ruby-prof, but is there an equivalent

Ruby: Libusb, one USB Device, two input endpoints = difficulties

I'd like to read out an USB Device in Ruby with libusb, which has two endpoints for input, once 0x81, which is in fact a Midi input Connector, and 0x82, which i

Write a program that adds together all the integers from `1` to `250` (inclusive) and `puts`es the total

How would I do this using ruby and only using a while loop with if, elsif and else only?

Ruby on Rails routes - Query parameter vs id

I'm trying to set a route that accepts a dynamic field. Restaurants have categories [:chinese, :fast_food, :french, :vegan] and the route restaurants/vegan allo

Flash is not displayed in the same view in Rails

I need to display flash in the same view (:edit) after successfully updating an object. If I redirect to another action - everything works correctly. But when I

Detect if block is given in Ruby define_method block

When searching, keywords 'block' and ruby 'define_method' keep telling me to explicitly define + call the block. Tried a bunch of stuff, including looking at so

How can I write this in haml? (rails app)

<a href="/"> <i class="material-icons">file_download</i> Export to CSV </a> I am using a material_icon gem. "file_download" is a do

Modify updated_at attribute through db trigger in rails

I was wondering if there is anything wrong about updating the updated_at attribute of a record through a db trigger in terms of fragment caching (i.e. the parti

How to ensure I can't add in integers or any numbers into an array via user input for ruby

I'm trying to create an array that only allows strings to be passed through, no numbers at all. Is there a way to make this possible? I've tried the below expec

Use current_user in hotwire partial

Hi I started using hotwire in rails app (currently I am working on adding comments) and I found that partials used for turbo streaming are free of global refere

Generate deterministic Namespace based md5 UUID from a string in java and ruby

I am trying to create a deterministic UUID in java to generate same UUID as we have in our ruby codebase but unable to do so and need help. #ruby code using uui

Ruby (or FFI?) error when executing Jekyll commands

I want to create a new Webpage using Jekyll, but when I execute jekyll new <page>, Ruby crashes with a really long Crash Report that starts like this: /Li

Ruby On Rails sort the array of hash based on priority

Please help me finding the solution sort by based on priority Im not getting the solution priority based on: 1st pick earliest slot 2nd max rating 3rd cronofy_e

Is there a way to seed a key with a value of an array of strings?

I'm trying to seed some data using an external trivia API. Here's what I have in my seeds.rb file where HTTParty is a gem that parses JSON into a ruby hash: res

Issue with Rails

I ran the command rail new friends After a couple of minutes I get the following error Installing bootsnap 1.11.1 with native extensions Bundle complete! 15 Gem

Sidekiq - SearchService::Errors::DefaultSearchException

While running Sidekiq I am getting this error: #<SearchService::Errors::DefaultSearchException: SearchService::Errors::DefaultSearchException> This is o

Ruby on Rails - javascript(s) folder and application.js missing

I'm new to Rails and trying to use some Javascript, but everywhere I go I see application.js mentioned, but it's nowhere to be found in my directories. I follow