Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Browsing all 4666 articles
Browse latest View live

What's the best way to parse JSON to a heterogeonus nested struct in Ruby?

Let's say I haveA = Struct.new(:name, :languages, :index)where :sections is supposed to be an array of items of this class:B = Struct.new(:language, :text)So, a JSON like this:{"name":...

View Article


How to use Jekyll github-pages with Ruby 3

I use Jekyll and Github Pages. However, when I run with Ruby 3, I experience errors when trying to serve the site locally. Specifically:$ bundle exec jekyll serve[...]jekyll 3.10.0 | Error: tried to...

View Article


What's the benefit of having a scope-resolution operator within the language?

For example: puts FileManagement::CSV.Reader.newWhy not: puts FileManagement.CSV.Reader.new?Why this differentiation? What's the benefit of having the additional ::-operator?

View Article

How to start sidekiq/bundler via systemd service on rvm

so I have a systemd service to run my rails application, which works great.[Service]Type=execUser=my-userGroup=my-userWorkingDirectory=/home/my-user/my-appExecStart=/bin/bash -lc "bin/rails...

View Article

ruby-on-rails docker image 632mb

I have done multistage dockerization of my rails app but the image size is over 600mb which is too high.Dockerfile# Dockerfile for local development.# Default Ruby version for this project.ARG...

View Article


What is the appropriate directory of permanent cache files wrote within...

I am developing a rubygem, which bundle a simple CLI.The CLI will make a web server request and cache part of its response to a text file.But, in development, I couldn't find appropriate place to store...

View Article

Shuffle array with exceptions

Is there a way to shuffle all elements in an array with the exception of a specified index using the shuffle function? Without having to manually write a method, does Ruby support anything similar?For...

View Article

How do I raise a fatal exception ruby?

Ruby has a fatal exception, but there is no guidance on how to raise it and I cannot figure it out. How do I raise a fatal exception in Ruby?

View Article


Parsing tomcat multiline catalina log with ruby regex in fluent-bit is not...

Below is my multiline log for catalina output:> 21-Aug-2024 04:51:02.916 INFO [http-nio-16500-exec-3]> org.apache.coyote.http11.Http11Processor.service Error parsing HTTP> request headerNeed...

View Article


When to use `require`, `load` or `autoload` in Ruby?

I understand the subtle differences between require, load and autoload in Ruby, but my question is, how do you know which one to use? Other than being able to "wrap" a load in an anonymous module,...

View Article

How to convert 1 to "first", 2 to "second", and so on, in Ruby?

Is there a built-in method in Ruby to support this?

View Article

Sum array values to hash

I have an array like[ [358, 202102, 5], [358, 202112, 5], [358, 202102, 10], [311, 202103, 5], [311, 202101, 1], [311, 202101, 1], [311, 202115, 8], [311, 202101, 1], [311, 202101, 1]]I need a hash...

View Article

Ruby: returning a hash of key value pairs up to a given length of key value...

Given a hash of arbitrary length, how do i return only a number of key value pairs (as a new hash) up to a certain point given as an integer?For example:hash = {a: 6, b: 2, c: 1, d: 5, e: 3, f:...

View Article


When do I have to 'require' a Ruby class in my Rake task?

I'm working on a Rake task which fetches a file via an external URL. To do this, I have to require the Net::HTTP Ruby class in my .rake file.This seems odd to me, because I've not loaded it in as a gem...

View Article

Not able to parse tomcat localhost access log via fluentbit reg ex

Not able to parse tomcat localhost access log via fluent bit using reg ex. Below is my incoming log:127.0.0.1 - - [27/Aug/2024:00:01:48 +0000] "GET /TA HTTP/1.1" 302 - 0Need output as below:Remote...

View Article


Can't use wkhtmltopdf-binary due to error "PDF could not be generated!"

Trying to execute tests on project and got errors with wkhtmltopdf-binary:Failed to execute: ["/home/o200/.asdf/installs/ruby/2.7.3/bin/wkhtmltopdf", "--margin-top", "5", "--margin-bottom", "10",...

View Article

Rails query output row # 1 and then continue to row # 3

Row # 1 only output 1 record continue the rest on Row 3- if @local_news.present? %h4.homepage-heading .row#local_news - @local_news.each do |news| .col-sm-12 = render 'news_article', article: news,...

View Article


Why are routing tests necessary in a RESTful API?

If I already have request tests like these:# spec/requests/articles_spec.rbRSpec.describe "/articles", type: :request do describe 'GET /show' do subject!(:action) { get("/articles/#{article.id}",...

View Article

rails cannot load such file -- mysql2/mysql2 (LoadError)

I am newbie to ruby on rails i could not find the solution for this error:rails s/usr/local/share/gems/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `require': cannot load such file -- mysql2/mysql2...

View Article

Getting Incorrect string value error with a 3-byte character that seems to be...

I got a Ruby On Rails project and a MySQL table/column with utf8 character set (collation utf8_unicode_ci), and I want to keep it this way for now.I wrote some code to clean invalid characters from...

View Article
Browsing all 4666 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>