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
11 views

Ruby Regex string validation

I'm trying to validate that a line in a text file is a specific format using regex. This is my method to perform the validation: def contains_directions(str) str.match(/^\d*\s\d*\s[NESW]{1}/) end ...
0
votes
0answers
6 views

Parsed_response in Ruby from HTTP

How can i get parsed_response from here? require 'HTTParty' require 'httparty/request' require 'httparty/response/headers' class CRUD include HTTParty def retrieve @@response = CRUD.get('http://...
0
votes
0answers
10 views

Checking if a text file is formatted in a specific way

I have a text file which contains instructions. I'm reading it using File.readlines(filename). I want to check that the file is formatted as follows: Has 3 lines Line 1: two integers (including ...
-1
votes
0answers
16 views

How to iterate over scrape data that returns each players names, points, and games they each have in ruby?

So I am pretty new to ruby and this what I had running in my program what I want to do is iterate over the tds instead of creating a method for each one. the site I am scraping is https://www.nba.com/...
1
vote
0answers
17 views

Trying to build a Jekyll plugin that adds YouTube thumbnails to links

I have a Jekyll setup that is working out well for me, but I would like to spice up my site by taking YouTube links that are inside their own <p> and automatically embed and image inside. I ...
0
votes
1answer
14 views

Why is Heroku having issues with my assets pipeline in rails 5?

I have completed my own portfolio website and went to push it to heroku. When I go to open the app it only showed a message saying: "We're sorry, but something went wrong. If you are the application ...
1
vote
2answers
31 views

How can I get the this ruby script to output the same rows and columns as another CSV file and add another column to it?

The goal of this script is to generate usernames for the useradd linux command. I also want to have the names same names in the same order be put into a new CSV file with the newly generated names and ...
0
votes
0answers
11 views

Rails + PostgreSQL: How to get products that have been ordered at least once + get the order # and the manager id

I have these models: class Product < ActiveRecord::Base has_many :orders end class Order < ActiveRecord::Base belongs_to :product end I want to get a list of all products which have been ...
-1
votes
2answers
19 views

Fix rails installation / openssl [closed]

I seem to have completely messed up my rails installation on Mac Catalina. I was working on a project which was running on the server just fine -> I then made the mistake of updating something, which ...
0
votes
0answers
18 views

Ruby parse invalid JSON

How can I parse the following JS object to a ruby object? It appears to be invalid JSON and it's driving me crazy. I'm trying to parse the HTML from view-source:https://www.zocdoc.com/doctor/adelle-...
0
votes
0answers
14 views

Why is using a variable to hold the results from a class method giving me this NoMethodError?

I was trying this practice problem on assigning attributes to columns in a table (more specifically the self.finalize! method): class SQLObject def self.columns return @columns if @columns ...
1
vote
2answers
40 views

Why is this ruby method not terminating at return?

newbie ruby question code challenge: string collapse: remove all adjacent duplicates in a given string. Note: removal of adjacent duplicates can create new adjacent duplicates, you must remove these ...
1
vote
0answers
27 views

Using merge sort for strings with numbers (ruby)

I am having some trouble with using merge sort for a particular type of inputs. The goal is to sort an array of strings with numbers like this: ["0 ab", "6 cd", "0 ef", "6 gh", "4 ij", "0 ab", "6 cd"...
0
votes
0answers
12 views

Where do I add the loop in my code to continuously search for a keyword until it reaches 100 searches?

loop do if client.search("Lebron",:result_type => "recent").take(100).collect do |tweet| client.search("#ruby -rt", lang: "en").first.text break end end end This ...
0
votes
1answer
20 views

Highcharts with Rails 6

I have a scatter chart made with Highcharts. I now need to add an image to the chart. The image should stick to the top right corner. I'm not sure if this is the best way to add an image, but I've ...
0
votes
2answers
31 views

Is there a base strip method in Ruby?

I have this snippet of code that I intend to use to get the first and last name from a CSV file to get a specific output. The end goal is to have the last name and first and last letter of the first ...
0
votes
2answers
23 views

how to avoid calling .all from this rails controller code?

how to avoid calling .all from this code? since .all will be load all the items to memory and slow I've tried to combine them but the code is not really that DRY companies_controller.rb def ...
0
votes
1answer
21 views

Why am I able to call the class method as if it were an instance method here?

I was looking through this example: class SQLObject def self.columns return @columns if @columns columns = DBConnection.execute2(<<-SQL).first SELECT "#{table_name}".* ...
0
votes
0answers
10 views

Error with rbenv at deploying rails 4 application with capistrano

I have rails app with capistrano and I use rbenv. I get error when running cap production deploy:restart DEBUG [62d2cfc8] Running /usr/bin/env [ -d $HOME/.rbenv/versions ] as someaddress DEBUG [...
1
vote
0answers
12 views

Subscribe only to a single stream with RailsEventStore

I intend to project a persistent read-model into a relational database with RailsEventStore. To make this possible I need an input stream with a fixed order and without duplicated events. Therefore I ...
0
votes
0answers
22 views

For each username, how do I create a user account using the Linux useradd command off reading a CSV file

I need to also ensure that the First and Last Names form part of the account information for each user. For example if the user's name is Allen Truth, I need to print Truthan and " The account for ...
0
votes
0answers
9 views

Is it possible to to only stub a call with specific parameters with minitest?

I have multiple calls to ::Foo.bar. I would like to stub only the call that includes a very specific parameter. Is it possible to do : ::Foo.stubs(:bar).with(1).returns(something) and still allow ::...
0
votes
0answers
5 views

c/jruby-9.1.17.0/bin/bundle: jruby: bad interpreter: No such file or directory

I follow some of the online tutorial and install jruby. But turns out, i don't need that so i uninstall it . But when i bundle install sh.exe": /c/jruby-9.1.17.0/bin/bundle: jruby: bad interpreter: No ...
0
votes
2answers
19 views

String/Hash Comparison Failure When Mocking Ruby HTTP Request With RSpec?

I've written a function that makes an HTTP GET request (truncated and simplified). # get_request.rb require "http" def get_request HTTP.get("<https://github.com>") end I've written a test ...
0
votes
1answer
12 views

How to scrape <script> tags with Nokogiri and Mechanize

I am attempting to scrape information from here. I need the address, phone number, and the desc. All of this info is accessable through normal html tags that can be scrapped using just nokogiri, ...
0
votes
2answers
28 views

Add validation to prevent out of range for ActiveRecord::Type::Integer with limit 4

I am running into out of range for ActiveRecord::Type::Integer with limit 4 error when typing a number over 10 digits. I want to add a validation to prevent this error from popping up. this is my ...
0
votes
0answers
12 views

Bootstrap in Ruby on Rails 6

I have installed bootstrap in my rails 6 and include inside my project a navbar, but I don't know how to change the style of navbar by sass - I follow Ruby on rails course on udemy but there are rails ...
0
votes
1answer
12 views

How to post XML string to api Ruby Faraday

I tried to use Faraday library for Ruby to make the next post request for my API: Need to add API-Key = "xxxxxxxxxxxxxxx" to my header and sent XML inside body <time_entry> <issue_id>1<...
0
votes
2answers
16 views

How to store in localStorage in Javascript from Ruby variable

I try to store a token in my localstorage from a ruby variable, As I understood, you can only set LocalStorage with Javascript, So here is my question, how can I pass my variable from Ruby to ...
-1
votes
0answers
15 views

Decrypting ActiveSupport::MessageEncryptor encrypted string in python [closed]

I have data encrypted by ActiveSupport::MessageEncryptor with salt(key). How should I decrypt that data with Python?
0
votes
1answer
13 views

ruby-kafka: is it possible to publish to two kafka instances at the same time

Current flow of the project that I'm working on involves pushing to a local kafka using ruby-kafka gem. Now the need arose to add producer for the remote kafka, and duplicate also messages there. And ...
0
votes
1answer
11 views

How to set SameSite attribute to 'None; Secure' in Rails3.1.12 and Ruby1.9.3

A cookie associated with a cross-site resource at https://example.com/ was set without the SameSite attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they ...
0
votes
0answers
7 views

How to verify OWASP 7.13 Keys and secrets are zeroed when destroyed

OWASP 7.13 says Verify that sensitive passwords or key material maintained in memory is overwritten with zeros as soon as it no longer required, to mitigate memory dumping attacks. Just ...
0
votes
1answer
23 views

Refactor with Strategy Pattern. In Ruby

Heads up! In the below example, using a pattern is probably overkill... however, if I were extending this to count genres, count the members in a given band, count the number of fans, count the ...
1
vote
2answers
34 views

Namespacing module method definition

I accidentally came across this piece of code in Ruby's Postgresql gem: ### Convenience alias for PG::Connection.new. def self::connect( *args ) return PG::Connection.new( *args ) end I played ...
0
votes
0answers
16 views

remove emojis from xml string or file even if they are encoded or not

I want to remove emojis from xml files. A typical exemple string could be something like <a> grve &#55357;&#56628; SNCF </a> and I want to have only <a>grve SNCF<...
0
votes
2answers
27 views

Convert YAML string to JSON using Ruby

I am able to convert a YAML file to JSON, but I am not able to convert a YAML string to JSON. Is there any other way to convert YAML string to JSON? Sample Input --- :name: :firstname: Guru :...
-2
votes
1answer
29 views

How to use query parameter like strong parameter?

How can i use query parameter as a strong parameter. This is my POST /tag method called by frontend to search posts. def tag if params[:category] == 'Shop' render json: ShopPostPopulator.new(...
0
votes
0answers
24 views

failed to allocate memory (NoMemoryError) when using RAILS_ENV=“production” bundle exec rails c

We just upgraded a Rails app to 4.2 to 5.2, everything is working like a charm in development, but when we try to release the app on our production servers, we can't run any rails related commands (...
1
vote
0answers
22 views

Safari push notification click event handle

I am worked on web push notification functionality in safari like chrome and firefox does. I have use apnotic and web-push-notification-rails gem for send push notification and it successfully ...
0
votes
1answer
22 views

Cron expression for running rake task first Thursday of every month

I have written following ruby code in rails application : every '20 8 1-7 * 4' do rake 'data_import:check_for_presence_of_file' end But above rake task is running ever day at 8:20 am GMT. Is there ...
0
votes
0answers
12 views

Architecture/design of creating/updating a dynamic invoice after creating/editing a reservation

For a room booking app, I created an app whereby a customer can book a: room additional options extra_guest not included in the room_price After a finishing the reservation, I'm create an invoice ...
0
votes
1answer
33 views

BUILD FAILED (OS X 10.15.1 using ruby-build 20191124) when installing ruby-2.4.0 with rbenv in OSX catalina(10.15.1)

I tried a lot of things from online forums. But never worked. Installed Xcode to see if it works. But it doesn't. At first, there was an issue with the C executables at the time of the OpenSSL ...
0
votes
0answers
20 views

Could not load OpenSSL while installing bundle in Mac OS

getting bellow error while executing bundle install in Mac OS Could not load OpenSSL. You must recompile Ruby with OpenSSL support or change the sources in your Gemfile from 'https' to 'http'. ...
0
votes
1answer
36 views

How can I get a Ruby Script to take a CSV File and separate it to get a specific output?

The goal of the script is to get the last name and the first and last letter of the first name and provide is as an eventual username for the useradd command. An example of this is: John Doe, The ...
0
votes
0answers
17 views

Calling a C function from mruby

Does mruby have the same FFI functions as Ruby? How do I call a C function from mruby? I am asking because I am considering the H20 web server with mruby scripting, but I need to be able to call c ...
1
vote
1answer
40 views

undefined method `-' for nil:NilClass in ruby model

I have defined a method inside my model class in ruby as below. But when I try using that method I am getting undefined method `-' for nil:NilClass. I am not able to figure out where I am going. bus....
0
votes
1answer
33 views

rename strong parameters rails 5

i have an issue with mapping third-party response to my server the response is "id": ".....", "external_id": "....", "recurring_payment_id": "....", "is_high": ..., "payment_method": "...", and i ...
0
votes
3answers
39 views

Where did this value variable come from?

I was reading through an example of how to use metaprogramming to make attribute accessors, and I'm a bit confused on where this value variable came from: class AttrAccessorObject def self....
0
votes
1answer
28 views

How to apply a custom validation to association in ActiveRecord

I have Item model and Theme model like so: class Item belongs_to :mobile_theme, class_name: 'Theme' end class Theme has_many :items enum theme_type: { desktop: 0, mobile: 1 } end I want to ...