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].

0
votes
1answer
5 views

Rspec shows Undefined method but the object is available in the same block

I'm checking some tutorials on rspec, This one seems weird. It does work in the tutorial but it does not in the live code. Would it be a version/deprecation issue? class Card attr_reader :rank, :...
0
votes
0answers
6 views

How to ignore the request body match for an specific host in rspec VCR?

I have ElasticSearch and Kibana integration with my rails application, and i use they for log and measure requests to external API's. I don't want that VCR match the body for ElasticSearch requests ...
0
votes
1answer
9 views

URL is altered after parsing with Nokogiri

str ="<?xml version='1.0' encoding='utf-8'?><url>https://somehost?p1=v1&p2=v2</url>" => "<?xml version='1.0' encoding='utf-8'?><url>https://somehost?p1=v1&p2=...
-1
votes
0answers
14 views

Ruby regex being commented out/not working

I have a bit of code: if word.match((http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?) However, the pattern gets commented out halfway through. Adding ...
0
votes
0answers
7 views

ostruct - unable to assign new field [duplicate]

I need to automatically populate field names in Open Structure. Field names are in an Array. How can I accomplish this? require 'ostruct' a = [] a[0] ='name' os = OpenStruct.new # os.a[0] ='...
1
vote
1answer
13 views

Can I query against the DEVISE current_user helper in my application menu?

The problem is, In the menu of my app I want to check if the current user has a book. If they do I will show a link to the edit book path, if not, I will show a link to the create book path. <% ...
0
votes
0answers
26 views

Model not inheriting from ApplicationRecord

I declare a model so it inherits form ApplicationRecord class ChassisGlazingPricing < ApplicationRecord; end Every model in my application that inherits from ApplicationRecord works fine. This ...
1
vote
2answers
53 views

Ruby .to_i does not return the complete integer as expected

My ruby command .to_i is creating strange result. "980,323,344.00".to_i returns: 980 instead of 980323344
0
votes
1answer
10 views

Redirect to nested routes with different controller

I have the next nested route redirect_to [:financier, product, section] This works if I have a controller with the name of the last variable but my question is how can I change the name of the last ...
1
vote
1answer
13 views

Unable to obtain peer certificate using HTTParty

I am on a MacBook (macOS 10.14.3) with OpenSSL 1.1.1b (installed via Homebrew), ruby 2.6.0 (installed via rvm), and HTTParty 0.16.4 (installed via gem/bundler). According to this example, it should be ...
0
votes
0answers
23 views

I can't create object from a class that has a foreign key for another class

I have two model Subject and Page, Subject has one page and the page belongs to one subject (one to one). When i tried to create object using rails console, it's ROLLEDBACK and didn't create the ...
1
vote
1answer
17 views

Hyperstack and MaterialUI Drawer Toggling State is causing the drawer to open and close repeatedly

I am implementing a title bar and menu drawer using MaterialUI in a Hyperstack project. I have two components, a Header component, and a Menu component. The Menu component is the expandable Drawer. I ...
1
vote
1answer
31 views

Custom validation not executing on creation of record?

I having an issue with my custom validation not validating a the date field on my form.My aim is to search the database for an existing date for the current user in appointment records.The flash ...
-4
votes
2answers
37 views

NoMethod - Undefined method <method name> error even if the method has been defined

I'm getting a no method - method undefined error while I am defining a method AFTER a particular method ends. The method defined before this one has an if..else statement block which might be creating ...
0
votes
4answers
58 views

Need a `values_at_if ` method to map values in ruby

I have two arrays of the same size response = ["N","N","Y","Y","Y"] mapping = ["A","B","C","D","E"] I need to select the elements in mapping whose corresponding value in response, i.e., the element ...
0
votes
1answer
8 views

Ruby Mail Gem Relay Access from Localhost to Postfix

I'm on a workstation that doesn't have a FQDN. I'm developing in Ruby and using the mail gem. I host my own mail server on the LAN. I want to forward outgoing emails to this server, off to a gmail ...
2
votes
0answers
41 views

how to test lock mechanism

I have a piece of code where I import a BankAccountTransaction to a BankAccount bank_account.with_lock do transactions.each do |transaction| import(bank_account, transaction) end end it ...
0
votes
1answer
24 views

How to not repeat code when looping over a data structure where a key's value can be a hash or multi-item array?

I have a complex data structure that looks as follows: ds1 = { 'item1' => { 'value' => '1024', 'flavor' => %w(s m l xl), 'platform_version' => %w(7), }, 'item2' => ...
0
votes
0answers
34 views

Passing data through URL to the other application in Ruby on Rails

I am new to Ruby on Rails, I would like to pass some data to my other application. I am currently using httpparty gem but I am having a hard time when I send big data such as text so I was wondering ...
0
votes
0answers
29 views

How to split parsers in Rails

I have question. I’m writing an application which parsing 10 webpages. I described each parser as a method of “parsercontroller”. The next step is to run 10 threads with 10 parsers, after the action ...
0
votes
0answers
24 views

rails runner start/end hooks

I have bunch of ruby scripts that being executed by the system using rails runner. Is there a common way to wrap the scripts to execute some monitoring before and after the execution of each script?
0
votes
2answers
30 views

how to return values in json that contain models to be associated using JBuilder

I would like to return values in json that contain models to be associated using JBuilder. But I don’t know how to do it. And I encounter the error that “undefined method xx” Here is my setting of ...
0
votes
0answers
15 views

Passenger + Apache is not spawning padrino app

Problem: My application is not starting, I believe it is because Passenger spawn server is not working after apache2 has started. Following is the error after apache2 has started /etc/init.d/apache2 ...
0
votes
1answer
27 views

Embedded Ruby form - validating email with specific domain

I am creating an embedded Ruby form and I would like the validation to allow 9 characters before the beginning, but specifcially starting with an 'x', so x12345678@a2z.ie would be a valid email while ...
3
votes
1answer
48 views

Ruby on Rails, convert projectwide single quotes to double quotes

I wonder if anyone has come up with a shortcut to correctly convert ALL single quotes to double quotes in a new rails project. Thank you in advance. I would do that at the end of generating new ...
0
votes
1answer
49 views

Instantiating a model and passing it a variable available in its body [on hold]

Given a model class Thing < ApplicationRecord end Is there any way I could instantiate it while passing it a variable, like so my_array = [:arbitrary, :data] my_thing = Thing.new(...
0
votes
1answer
40 views

How to remove quotes from strings in an array?

Assuming I have the following input: names = ["\"Петр Сергеевич\"", "\"Курсатов Роман\"", "\" \"", "\"Павел2 Олегович\"", "\"Илья иванович\"", "\" \""] Each whitespace is actually a non-breaking ...
-2
votes
0answers
16 views

How to install mysql2(gem) in Logstash’s ruby filter

I want to exec mysql statement in Logstash’s ruby filter. the vender mysql2 gem is required. how to install mysql2 gem? input { ... } filter { ruby { init => " require 'Mysql2' " ...
-3
votes
0answers
21 views

How to use sticky session on URL in HAProxy [on hold]

I want to use 'stick' on a URL with regular expression. The URL could be, for example: '/api/v1/products/asdas123' [sic] '/api/v1/products/asdas123/line_item/asdsdf234' '/api/v1/products' '/api/v1/...
-4
votes
0answers
35 views

Find the closest value based on prefix from one set of numbers

I have these numbers: 18763044 187635 23092 3162 38050 33 49185 51078 1246 and this table: +--------+-------+ | CC | CODE | +--------+-------+ | 599 | ANT | | ...
0
votes
1answer
41 views

Why does map function mutate array of objects when operating on each element's attribute?

I have an array of objects: class Person attr_accessor :email def initialize(email) @email = email end end array = [ Person.new('hello@gmail.com'), Person.new('world@gmail.com') ] I ...
-1
votes
0answers
16 views

Implement a simple event dispatch pattern using Ruby

I want to implement an event dispatch using Ruby. An object ExtButton can dispatch an event to an object ElevatorSystem Multiple Exbutton instances will have the ability to dispatch events to the ...
1
vote
1answer
17 views

Is there a way to disconnect console messaging from Hyperstack message queue?

In Hyperstack every state change enters a message queue through a websocket mechanism to inform every application client for model/app state changes. So if you update a model from my browser sessions, ...
1
vote
5answers
51 views

Most elegant way to create hash from two datasource

I have a building_table and api::building_table, I would like to have the data from building_table as a default but if the data doesn't exist in building_table I would like to have to get it at api::...
0
votes
1answer
28 views

form_with model altering url parameters for edit form

The REST route for EDIT is overriding the first URL parameter in addition to the last URL parameter but other parameters are unaltered. How do I stop the form from changing the url first parameter? ...
0
votes
0answers
35 views

Associated param not going through, but others will? Why?

Issue: Specific record from associated model won't pass through on create, but others from the same associated model will.... I have the following in my create for UserProducts: def create ...
-2
votes
3answers
37 views

Why does a substring with indexes [0, 1] return two characters, including the escape backslash?

I have: long_string # => "\nIt was the best of times,\nIt was the worst of times.\n" I get: long_string[0,1] # => "\n" I am curious why I get two characters rather than merely "\" as in ...
0
votes
1answer
22 views

Rails 5.1 API - index method with filter, pagination and scopes - how to simplify

I have an index method in a Rails API controller that is quite horrendous, as you can see below. I am sure there is a more Ruby or Rails way to write this. The action supports paging and filtering (...
1
vote
2answers
36 views

Ruby search in http get request response body

I'am making a get request in ruby like; require 'net/http' require 'uri' uri = URI.parse("https://www.test.com") request = Net::HTTP::Get.new(uri) request.content_type ="...
0
votes
3answers
46 views

Ruby equivalent to Python chain()

What is the Ruby equivalent of the chain iterator in python? data_chained = [] data2 = {} data_chained = chain(data_chained, data2) How can this be done in Ruby?
1
vote
4answers
54 views

How do I transpose two hashes in ruby to make a single hash or array?

I want to take the two hashes below and combine them into a new hash or array: hash1 = {1=>"]", 2=>"}", 3=>")", 4=>"(", 5=>"{", 6=>"["} hash2 = {1=>"[", 2=>"{", 3=>"(", 4=&...
3
votes
2answers
59 views

Is there an alternative to use of the method Array#product? [on hold]

I am using the method Array#product with several arguments that are large arrays. The receiver is also a large array. Consequently, the resulting array is huge and consumes an excessive amount of ...
1
vote
0answers
46 views

CSV.foreach Memory usage keeps increasing

My import speed is slow, it takes 2.5 hours to process a 13K line CSV file. I am wondering why my memory usage keeps going up, as I increase the file size? I am using foreach, so I thought memory ...
0
votes
1answer
26 views

How to pass param alongside model param to controller

Right now I am passing a model(building_approval) params via form. Processing by BuildingApprovalsController#update as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"FdZWpexusIHZ/...
1
vote
2answers
38 views

reading parameters from create method

I have a ruby on rails project that is using the devise gem for authentication. I'm trying to use a captcha form in the sign up page to prevent bots from creating thousands of dummy logins I'm not ...
-2
votes
1answer
43 views

How to avoid syntax error when starting my app [on hold]

I'm developing my Ruby Notepad application and receive strange error: notepad.rb:12:in `require_relative': /home/orkos/Notepad/task.rb:24: syntax error, unexpected end-of-input (SyntaxError) In my ...
0
votes
0answers
16 views

Sending array to get with Grape API

I am trying to test this route with Grape API params do requires :ids, type: Array end get 'route' do present find_by_ids(ids), with: EntityName end I have tryed this: ...
1
vote
0answers
30 views

In Rails, use nested_form for adding items to table rows do not work in production environment

I'm using simple_nested_form to add items to table rows, directed by this https://github.com/ryanb/nested_form/wiki/How-To:-Render-nested-fields-inside-a-table. It works very well in development ...
-2
votes
1answer
42 views

How am I supposed to have inherited variables in Ruby?

I am trying to achieve: class Model table ="NOT SET" self.get(id) sql ="SELECT * FROM #{table} WHERE id = #{id} end end This is my generic model class with an example function. ...
0
votes
0answers
9 views

Parser filter plugin not working Td-agent [Fluentd]

My environment for running fluentd using td-agent is below:- fluentd or td-agent version. td-agent 1.3.3 Environment information: Operating system: cat /etc/os-release NAME="Ubuntu" VERSION="16.04.5 ...

http://mssss.yulina-kosm.ru