How to use Rack::RewindableInput::Middleware in a Sinatra Ruby app?
This is the code that works just fine:require 'sinatra'post '/foo' do"Equals to #{params[:a]}!"endIf I send POST request, it returns all right:$ ruby foo.rb -p 8888$ curl -X POST -H 'Content-Length: 5'...
View ArticleRails - How to Create Association to 2 Sub-classes Part of SIngle Table...
So I have set up Single Table Inheritance so I can create two sub-classes for the User table. In my current implementation, both subclasses will have the exact same fields so STI makes sense here I...
View ArticleHow can I get correct indentation in neovim for Rails?
Using Neovim does not seem to give correct method arguments alignment (i.e. conformant with the Ruby and Rails style guides).Specifically, this example: redirect_to @foo, notice:...
View ArticleHow to shorten a UUID to a given length?
I'd like to use a UUID for database records but if I'm using it for the URL I'd like it to be 5 to 8 characters.I know I need to use SecureRandom and base64, but how do I specify the length I need?
View ArticleSearchkick as a client only
I'm working at a Ruby software which is divided in services (not micro, just services). Some of these services have the Searchkick gem installed (https://github.com/ankane/searchkick) and index data by...
View Articlein `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError)
After deploying a new rails app to Heroku I'm getting a NoMethodError. Everything works fine locally. I'm unsure how to and where to add the method.I'm new to ruby (coding in general) and it seems to...
View ArticleError while decrypting file using PGP decryption in Rails
I have a client file which is encrypted using PGP encryption. The encrypted file shared is in xlsx format. The PGP private key is also shared as a text file(Note that i added .pgp extension for the...
View ArticleStandard way for Rails to parse array query params without using brackets in...
I want a resource URI to look like this:https://domain.tld/resource?param=foo¶m=bar¶m=bazBut Rails requires array query params to use the square bracket notation. Before URL escaping,...
View ArticleRuby version issue in osx 14.4
Okay, so... I have an M1 chip machine, with OSX 14.4 running on it. I wanted to install Ruby 3 with some gems and strange things happened... I used RVM for installing 3.4 onto my machine which was...
View ArticleRuby On Rails - Turn If Else Statement Wiith Match? To Case Statement
How do I turn the following if / else statement: if /_?town$/.match? name ['Springfield', 'Shelbyville', 'Kent', 'Carter', 'Benson'].sample elsif /_?state$/.match? name ['TX'].sample else'text' endinto...
View ArticleRails 7 - How to update a model with skipping the validation?
When I try to update some attributes in a modelmy_model.update!(attr1: 'val 1', attr2: 'val 2', attr3: 'val 3') I get an errorActiveRecord::RecordInvalid: Validation failed: MyModel must exist,...
View ArticleRMagick installation: Can't find MagickWand.h
Updating RMagick and Imagemagick is a painful expierence. I have updated the Imagemagick version on my mac (MacOS El Capitan Version 10.11.5) with homebrew for one project in Ruby 2.3 to 6.9.5-9$...
View ArticleRuby not working on windows term 'rails' is not recognized
I’m using Windows 10, installed Ruby 2.6.14 and bash 4.3.42(5). And I can’t run ruby, the error follows below:PS F:\App\App> rails crails : The term 'rails' is not recognized as the name of a...
View ArticleHow to use amazon accelerate with md5 on s3?
I am using uppy aws-s3 to upload my file using this code:this.uppy.use((await waitForPromise(import('@uppy/aws-s3'))).default, { limit: this.token.payload.upload_concurency, getUploadParameters: async...
View Articleruby: multithreading in a docker container does not work
I tested ractors in ruby with docker and withoutthis is my scriptractors = []Benchmark.bm do |x| x.report("Single thread:") do cpu_intensive_task cpu_intensive_task end x.report("Two ractors:") do...
View Articleruby number to human-readable string conversion
I need to have a list with id's for each list item being #one, #two etc.Is this the most efficient way or am I missing an in built ruby function here?-num_array = ["one", "two", "three", "four",...
View Articleimage_tag not returning image using url in service
module FileService class LetterGenerator def initialize(user) @user = user end def process WickedPdf.new.pdf_from_string( ApplicationController.new.render_to_string( template: 'services/main.pdf.erb',...
View ArticleWhy am I getting a CSRF token authenticity error when trying to submit a...
I connected a form_with with my stimulus controller, then added the form itself as a target and added an action to point to my stimulus controller's submit function. When I then get the form and try to...
View ArticleIn Ruby, how to set a default value for a nested hash?
I recently looked for a way to correctly create and use nested hashes in Ruby. I promptly found a solution by Paul Morie, who answered his own question:hash = Hash.new { |h,k| h[k] = {} }I promptly...
View ArticleAudio streaming using metasploit
I want to make a microphone audio stream in metasploit like webcam_stream,so I added some codes to the ruby script at :...
View Article