Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [ruby]

Ruby is a multi-platform open-source, dynamic object-oriented interpreted language, created by Yukihiro Matsumoto (Matz) in 1995. The [ruby] tag is for questions related to the Ruby language, including its syntax and its libraries. Ruby on Rails questions should be tagged with [ruby-on-rails].

Filter by
Sorted by
Tagged with
0
votes
0answers
9 views

How to fix “Authentication plugin 'caching_sha2_password' cannot be loaded” with [email protected]

Database creation fails with Authentication plugin 'caching_sha2_password' cannot be loaded error. Above error occurs when I run following command: $ RAILS_ENV=test rake db:create Error message: ...
0
votes
1answer
16 views

iterating over to make hashes within an array

so I know how I can iterate over and make array within hash travel=["Round Trip Ticket Price:", "Price of Accommodation:", "Number of checked bags:"] (1..3).each_with_object({}) do |trip, travels|...
1
vote
2answers
17 views

How does I18n set locale if http header support multiple languages

if accept_language in http header is simple and straightforward like: 'en' or 'en-us', Setting I18n's locale is easy, just like: I18n.locale = request.env['HTTP_ACCEPT_LANGUAGE'] But what if the ...
0
votes
1answer
12 views

Ruby: add methods to an already-instantiated object?

I know how to use include to add mixins to a class in Ruby. However, I want to add one or more methods to an already instantiated object. Is that possible? For example, the Rack::File::Iterator class ...
-2
votes
1answer
19 views

adding user input into hash

I want to ask three different users, three questions. I want to add their responses to an array which will be the value pair of a hash. I'm looking for something like this. myhash={ "person1"=>[1, ...
-1
votes
1answer
36 views

Pulling out values from element of array

I have a hash that is generated by IB-ruby and looks like this: {:contract=>#<IB::Stock:0x0000560721a1aee0 @attributes={:symbol=>"AAPL", :currency=>"USD", :sec_type=>"STK", :created_at=...
0
votes
1answer
35 views

Best way to process data in a Rails service

I have a reminder service which takes some 'changes requests' and then sends them to a worker queue to perform at a later date. Each 'change request' can either have a 'ten minute before' reminder and ...
0
votes
0answers
13 views

After submit nothing happend using Mechanize

When I tried to submit a form I got this output: => #<Mechanize::Page {url #<URI::HTTPS https://host.com/Admin/Login.aspx>} {meta_refresh} {title "Edito .NET - Admin panel"} {iframes} ...
2
votes
2answers
48 views

What is Ruby doing with gsub here?

I'm working on converting code from Ruby to Node.js. I came across these lines at the end of a function and I'm curious what the original developers were trying to accomplish: url = url.gsub "...
0
votes
1answer
24 views

Rails Minitest Has Many And Belongs To Model Test ActiveRecord::UnknownPrimaryKey Error

When I try to run minitest with simpleCov, I want the join table model UserMessages to be covered. I have setup fixture, to run test and keep getting an ActiveRecord::UnknownPrimaryKey error. This is ...
0
votes
0answers
23 views

What's the difference between Kernel.require and Kernel.gem_original_require?

Consider the following script: module Kernel unless defined?(gem_original_require_2) alias gem_original_require_2 require private :gem_original_require_2 end def require(path) ...
0
votes
1answer
21 views

Ruby set time zone *without Rails* [duplicate]

Is there any way for me to tell Ruby to use a certain time zone as if it were the local time zone? TMI: I realize that in Rails there is a lot of support for time zones, but I've just been put on a ...
0
votes
2answers
43 views

How to capture all lines between two lines in regular expressions with ruby? [on hold]

Suppose I have the following text: 0000000000401040 <[email protected]>: 401040: ...
0
votes
5answers
52 views

How to verify that the last character in a string is a number

I need to check if the last character in a string is a digit, and if so, increment it. I have a directory structure of /u01/app/oracle/... and that's where it goes off the rails. Sometimes it ends ...
1
vote
1answer
21 views

how fix error? ' …rubocop- … revealed dependencies not in the API …"

how do I fix this error? +bundle install --jobs 3 --full-index --retry 3 --deployment Warning: the running version of Bundler (1.17.2) is older than the version that created the lockfile (1.17.3). We ...
2
votes
2answers
32 views

How to get a block at an offset in the IO.foreach loop in ruby?

I'm using the IO.foreach loop to find a string using regular expressions. I want to append the next block (next line) to the file_names list. How can I do that? file_names = [""] ...
1
vote
1answer
30 views

ActiveRecord - Query with Condition of Last Element in Association

Trying to do a sort of complex query in ActiveRecord right now. Not sure if it's possible to do entirely in ActiveRecord (i.e. without just filtering intermediate results in Rails). I'd like to do as ...
1
vote
1answer
17 views

How encoded filename in S3 Presigned url in ruby

in S3 presigned url how I can encoded the string $filename s3.bucket(ENV.fetch('S3_BUCKET_NAME')).presigned_post( key: "uploads/#{Time.now.to_i}/${filename}", allow_any: ['authenticity_token'], ...
0
votes
2answers
36 views

Ruby don't do actions for nil class in if block

How to achieve sth like if params[:filters][:company_name] is present (not nil) then do below actions but if it's nil - skip and do the rest of the code below/outside of this if ? if params[:filters][...
0
votes
0answers
11 views

ElasticBeanstalk Execution Expired When Configuring LogStreaming

I'm getting an error I've never encountered before. I have a multi-region stackset that builds an ElasticBeanstalk application in two regions (us-east-1 and eu-west-1). The configurations are exactly ...
1
vote
4answers
39 views

Find N number of common attributes in an array of structs

I have the following struct: Name = Struct.new(:first_name, :last_name) do def greeting "Hello #{first_name}!" end end I am adding these objects to an array like this: full_names << ...
-1
votes
1answer
38 views

Another one “undefined method `[]=' for nil:NilClass” error

what's wrong with this code? I have a .txt file wich consist some attributes like that: attr_one, att2, attr3, attr4 attr_one, att2, attr3, attr4 attr_one, att2, attr3, attr4 I want to change "...
0
votes
1answer
15 views

How to access an environment variable that's a bash array from a Ruby ERB script?

How does one loop through an environment variable that is a bash array in a Ruby ERB? I'm aware that this can be done with arguments anyway <%= @args[x] %> And you can get to Environment ...
1
vote
0answers
4 views

Dynamic search filter in Rails/Grape to show blank page

In my app after pressing the filter button a search field appears - searching companies by company name. Everything works well but I'm just wondering how to implement scenario where user enters ...
0
votes
0answers
9 views

Issues when adding devise-jwt to a existente User model in Rails

Im trying to add the devise-jwt to an existent app I have. Im adding API endpoints now, and want to use the same Model I have already I added the gem devise-jwt following this article here: https://...
0
votes
0answers
33 views

How to use multiline-string here-doc with interpolation using enumerable or loop blocks

I want to simulate the usage of ERB templates using blocks into multiline-heredoc in Ruby: Example: From: <html> <body> <ul> <% @greetings.each do |greeting| %> ...
0
votes
1answer
27 views

Action Controllers and filtering

I'm developing an app where an admin can see a group of users in HTML tables that are filtered by ":platoon => A,B,C,D" All users are stored in a "users model" and I'm trying to have multiple HTML ...
0
votes
1answer
31 views

Instance variables assign value by reference in ruby

I have a doubt that in ruby whether all the objects in ruby pass or assign value by reference. Because when I tried to assign a instance variable to local. Changes made to local affects in instance ...
0
votes
0answers
18 views

Inject code in .pch files from Pods, in post_install

I have tried several approaches to modify the prefix_header_contents property from cocoa pods post_install, but nothing worked. I basically want to include some code that will block NSLog from pods, ...
0
votes
2answers
28 views

Getting Error on “compass compile” after upgrading to Catalina

Looking for the solution, since I'm now out of ideas how to fix that. Before I upgraded my Mac OS X to Catalina everything was fine. What I tried already: removed ruby sudo rvm implode and all the ...
2
votes
2answers
50 views

Two way lookup of id vs name ruby

I have a hash in which id is the key and name is the value. Both id and value are unique. Something like this: h[1] = "ABC" h[3] = "DEF" So, if I am given the key of 1, I can easily return a value ...
0
votes
1answer
10 views

Is HTTP/2 supported in Typhoeus

I cannot find any information about support HTTP/2 features in Typhoeus gem. Is this fully compatible or not?
0
votes
1answer
39 views

How to access to a shopcart. Couldn't find LineItem with 'id'=2

I'm making a Ecommerce site with rails.Trying to create a shopingcart. When I added , include CurrentCart before_action :set_cart to my application_controller.rb , I got this error. I checked with ...
0
votes
0answers
10 views

There is no ` install.rb ` file in the decompressed facter directory

I follow the document: Unarchive the Facter, Hiera, and Puppet tarballs, then navigate to each resulting directory and run: sudo ruby install.rb I download this facter file tar.gz, ...
0
votes
0answers
10 views

Setting up an HTTP server with CORS enabled inside a Smashing/Dashing job

I am making a web app consisting of two parts: Smashing dashboard containing custom widget displaying progress for a given set of JQL queries from Jira; and a webform hosted on an apache server used ...
0
votes
1answer
18 views

Soft Delete has_and_belongs_to_many association using discard gem

What is the best way to soft delete has_and_belongs_to_many associations using Discard Gem. With this association, there is a join table in database but without actual Ruby on Rails Model. I'll try ...
0
votes
0answers
28 views

How do I keep track of the endpoints being hit for a request?

I am a newbie Web/Rails developer. The codebase(uses multiple docker containers) that I have been provided with is quite vast and when I am assigned issues to solve, it is difficult to understand ...
0
votes
0answers
26 views

How to solve a problem when clicking the shopcart. Couldn't find LineItem with 'id'=2

I'm making a Ecommerce site with rails. when I try to click the add to cart link this error appears. I really appreciate it if you could give me a hint to solve this problem. Sorry for the long codes. ...
1
vote
2answers
46 views

How to build a monthly range that takes in account the number of days of each month?

I have a range with a start_date, end_date and I want to get the same day of each month for the whole range, so here starting on the 30th of January I should get the 30th of each month: start_date = ...
0
votes
2answers
27 views

Getting zero and not the expected output in recursive factorial?

Not getting the expected output, only get 0 when I enter any value 5 or 6 or 7. I need to use ARGV to enter the value in the terminal. Need a single argument with a value 0 or higher. For testing Try ...
1
vote
1answer
21 views

how to migrate ruby-sass custom functions to sassc?

How do I migrate this ruby sass custom function to SassC? In a rails project, I just included this module in my application.rb and the likes of my-method would be available in my sass files. The ruby ...
0
votes
1answer
42 views

How to find the original email in a forward using the Mail gem

How do I use the Mail gem for Ruby to extract the original message HTML content/text content from a forwarded email? So far all the examples I see are related to extracting content from replies (not ...
1
vote
1answer
28 views

Zeitwerk, require_dependency and splitting Ruby classes into a few files

Before Rails 6 there was a simple way to split any Ruby class into multiple files without introducing any additional modules or concerns. It was quite useful for those God classes which happened to be ...
0
votes
3answers
44 views

Show records only belonging to that user ruby on rails

I have the following code <div class="container mt-4"> <div class="card"> <div class="card-header"> <h5>Name: <%= @user['name'] %> | Username: <%= @user['...
0
votes
2answers
29 views

display nested JSON in ruby on rails

I believe this is going to be an easy fix but everything I'm trying isn't working. I'm getting data from an external API and I'm looking at display the data after matching the ids. The data is JSON ...
0
votes
0answers
33 views

i386 arch error installing old scrypt gem version with OS Catalina 10.15

I'm trying to install an old gem version for an old project after a fresh install of OS X 10.15 Catalina and XCode Command Line Tools and Xcode 11.0. The gem I'm trying to install is scrypt, version 1....
3
votes
1answer
30 views

block_given? always returns true in erb templates

In Rails 5.2.3, I need to render a partial which takes an optional block. # users/_user.html.erb ... <% if block_given? %> <%= yield %> <% else %> <h1>Goodbye world</h1&...
1
vote
1answer
34 views

display other data within `each` ruby on rails

I have an application where I'm displaying albums and users I'm currently outputting the albums, <main role="main" class="flex-shrink-0"> <div class="container"> <h1 class="mt-5"...
4
votes
0answers
32 views

Reify only one has_many :through association with PaperTrail?

I'm using the paper_trail-association_tracking gem to save PaperTrail versions for AR associations. I have a model, let's call it User, that has many Groups and has many Skills. Both of these ...
0
votes
1answer
34 views

How can I require a model and use it

I would like to know how can I require a model of my rails project and use it. Let's say I have the following structure: app/ constrollers/ users.rb models/ users.rb By default I can ...