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

1
vote
1answer
35 views

How to quickly generate an array from strings in Javascript

In ruby I can use the following code to generate an array of strings from a to z: alphabet = ('a'..'z').to_a => ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",...
0
votes
0answers
20 views

I already assign 2 arguments on initalize method in ruby. But there's a (given 2 ,expected 0) ArgumentError

There's a very small RUBY code in here. I assign 2 arguments on initalize method which is name and price. But compiler expect me 0 arguments. I've tried product1.name ="hp laptop" and it ...
0
votes
0answers
17 views

Apply deep_symbolize_keys! to array of hashes

deep_symbolize_keys! converts string keys to symbol keys. This works for hashes and all sub-hashes. However, I have a data like this: arr = [ {'name': 'pratha', 'email': 'p@g.com', 'sub': { 'id': ...
0
votes
1answer
17 views

Is the :through association the correct way to link a joint table in Ruby on Rails

I have 3 tables named Users table, Messages Table and the Message_users Table and the Users table will be be used to store users' info while the Messages table will ...
1
vote
2answers
23 views

RegEx for matching 3 alphabets and 1-2 digits

I am trying to write a regular expression to find a match in a text having at least 100 characters. The match should be like this - Any sub string within a string that contains at least 3 alphabet to ...
0
votes
0answers
16 views

Purging a active storage attachment will not delete attachment record

I have a model "Account" configures as: class Account < ActiveRecord::Base has_many_attached :images end When I try to delete image/images, respective record from "active_storage_blobs" and "...
0
votes
0answers
11 views

Ruby cannot get Azure VM metadata from Azure Instance Metadata service

According to MS documentation https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service Azure provide instance metadata service at "http://169.254.169.254/metadata/...
2
votes
1answer
33 views

My Rails Aplication start to raise ActiveRecord::ImmutableRelation in some random queries

since yesterday, my production app starts to raise ActiveRecord::ImmutableRelation in some queries of my entire application! I can't imagine how to gives an exact context of every error since this ...
0
votes
2answers
24 views

Print the first letter in the view but I don't need to repeat the letter

I'm making a list of categories but I need the header to only show the first letter without repeating This is for a list of all the categories of a store Controller: def show @category = ...
0
votes
1answer
20 views

Capybara attach_file not triggering React onChange handler in Firefox

I'm testing file upload functionality on a page built with React. The React page has a hidden file input field with an onChange event listener wired up to it. When a file is selected it triggers the ...
0
votes
2answers
27 views

Ruby on Rails: link_to vs button_to

I am having trouble implementing the method link_to. My program uses a link to call a controller method which performs some logic and renders a partial. The issue is I cant get the link to call the ...
1
vote
1answer
24 views

Ruby: Store and update variable inbetween script runs

Newbie at ruby here: I need to create a ruby script that will be executed multiple times as I receive different event data. Each time an event is received, this script will be run. I'd like the ...
0
votes
4answers
44 views

How to get even groups in ruby?

Let's say I want to get a certain number of even groups based on a collection of records with varying count. How is this possible? I'm looking for a method like objects.in_x_even_groups(4) Update: ...
0
votes
0answers
13 views

Internal Server error when trying to login into the system for the second time

I have a ruby-on-rails application which is linked with siteminder for its login module. Once the user log's in using the siteminder credentials it list them all the app they have access too. once of ...
0
votes
1answer
18 views

rails model call back before_validation

I am using rails 5.2.3 If I inherits Active Record I can definitely use before_validation callback. But I only use include ActiveModel::Model like this # MortgageAmount model class MortgageAmount ...
0
votes
0answers
16 views

Gmail API Global Per Second Rate Limit

I need to be able to correctly catch and handle global rate limit errors returned from the Gmail API. How will I be able to differentiate between per-user rate limit errors and global rate limit ...
0
votes
1answer
13 views

HERE maps api (js) problem after traveling back from another link

I'm building an app with ruby on rails and I just implemented a map service with the 'HERE interactive maps' API in the view, with the javascript code. It works properly but if I click on a link and ...
0
votes
1answer
22 views

Proper way of selecting related objects by multiple rows

Say I have 3 tables: Houses has_many Wardrobes has_many Clothes. houses wardrobes clothes ------ --------- ------- id id id name house_id wardrobe_id name ...
0
votes
1answer
40 views

How to prevent classes to be overridden in Ruby?

I'm setting up rules how to write minitests, and I want to prevent other programmers to override methods for existing classes, because it will affect other tests, where this class will be used. Here ...
0
votes
2answers
28 views

Take name of variable as input and output its value - Ruby

I'd like to know if there is something Ruby that does something like this: @my_var ="foo" some_function_i_dont_know_name_of("@my_var") => "foo"
0
votes
1answer
26 views

Rails 5 app not saving certain attribute/association only in the production environment

I have a bug that's not allowing me to save an association. It's only not saving in the Production environment hosted by Heroku. After running the code below, the object will be saved with ...
0
votes
0answers
22 views

How to handle after_create error? (trying to create webhook)

I am new at backend developing. Sorry for my English. Now I am working at RoR app using Trello Api. I have Relation model in my app. I need to create webhooks after Relation object was created. But ...
0
votes
1answer
15 views

How to test private helper(module) method in rspec

I have a helper module named "AppHelper" and private method "sum" which I want to test using rspec. For example: module AppHelper private def sum(a,b) puts a+b end end
1
vote
2answers
29 views

ruby - how to created SortedSet from Set?

If I have an array I can create a set (unique values) from it with require 'set' s = [11,12,3,2,3,4,3,5,89,1,2,3,4] uniq_s = s.to_set # gives [11,12,3,2,4,5,89,1] If I want the result to be sorted I ...
0
votes
2answers
31 views

How to check the on change event in multiple elements with same class name in Rails using Jquery

in a rails module, when user enters less than 0 value he should get invalid message. in js file i have written a onchange function which expecting when a textbox gets less than zero value this ...
0
votes
1answer
17 views

Why find(element).click uses max_wait_time instead of the specified wait:0 if the element is not clickable?

Background: checking if element is clickable (I expect it to be not clickable, I want to assert this) without waiting. find().click uses Capybara.max_wait_time and then returns exception: Selenium::...
0
votes
1answer
31 views

Dividing authenticated and unauthenticated layouts in Rails with Devise

I just started a new Rails (6.0.0.rc1) application and included Devise for authentication. Now, Devise comes with a lot of views that are used for registration, sign in and so forth. Naturally I want ...
0
votes
0answers
13 views

Rails - Mongoid : Slow problem between production and development

I have a problem on my Rails application. I am in version 3.2.22 of rails and 2.2.5 of ruby connect to a mongodb 2.6. The problem is that I have huge difference in performance on simple or even more ...
0
votes
1answer
30 views

Deleting custom data type elements from an array based on their attributes

I'm making a calendar application and one of the functions is to allow the user to delete any preset activities of his choice. My current code gets the users input for their selected day, and displays ...
0
votes
1answer
48 views

is there a way to specify class unextendable in ruby?

as we use "final" keyword to declare a class non-extendable in java. How do we achieve this in ruby? is there any way?
0
votes
1answer
23 views

Change Position of Existing column in Rails

I have one Column in my Table, i want to change its position from last to second, can anyone please help me to do that. thanks in Advance.i have idea about after: column_name, but its apply while ...
1
vote
4answers
36 views

How to remove a part of string?

I am new to Ruby and currently I am trying to take out a part from the http request string. Request : POST /test/userRegistration?id=1234&name=John&address=UK Is there any way to take out "...
0
votes
2answers
55 views

undefined method create product/ for nil class

There're two problems I encountered in the codes below, I was trying to do @products.each do |product| but it threw me back undefined nill class on product - I've checked the problem in product ...
0
votes
1answer
17 views

Getting BUILD FAILED when trying to install Ruby via rbenv on Mac OS X 10.14.5

I'm trying to install Ruby using rbenv but it keeps ending up with a BUILD FAILED message. I've tried reinstalling Xcode, rbenv, and homebrew without any success. I'm running: rbenv install 2.6.3 ...
0
votes
0answers
29 views

scroll into view not working on selenium webdriver - Ruby + watir-webdriver using for automation

We are using ruby + watir-webdriver for our UI automation. recently we have upgraded our firefox from 52ESR to 60ESR. for that we upgraded selenium web-driver from 3.3.0 to 3.4.0 in gem lock file. now ...
2
votes
1answer
30 views

How to do proper Git compatible hex sha packing/compression in Go

I am going through the book Building Git by James Coglan, where James walks you through implementing a basic version of Git in Ruby. I decided to make things more complicated for myself by doing my ...
0
votes
1answer
21 views

How to get target's version by Ruby (or Xcodeproj)

How to get target's version(The version of you APP) in Ruby or Xcodeproj? I have tried sdk_version in AbstractTarget with Xcodeproj, But it returns nil. If Xcodeproj doesn't support it. How to get ...
1
vote
1answer
34 views

How to find the Closest point of a line string to a given location - rgeo

My point coordinates are in geographic coordinate systems. They are in memory. I need to find the nearest point on the line string to a given point using RGeo library from Ruby. My scenario is the ...
1
vote
1answer
34 views

How to handle incorrect git/hg clone command in ruby

Is there a way to handle trying to clone a repo that does not exist gracefully? In ruby, I can clone a repo like this: system("hg clone https://username@bitbucket.org/username/repoThatDoesNotExist") ...
-3
votes
1answer
43 views

How to get multiple input from one line in ruby

How to get multiple input from one line using ruby. I know how to do it using Java. System.out.print("Enter three points for the triangle: "); double x1= input.nextDouble(); ...
0
votes
0answers
36 views

How to support multiple databases (postgresql) with Sidekiq server for the same project?

I want Sidekiq to support multiple dynamic databases for the same project desc "Start sending the client invitation" task "sidekiq:start", [:database] => :environment do |task, args| database = ...
2
votes
3answers
77 views

Does Ruby have a `bool` function like Python?

In Python I can determine the boolean value an expression evaluates to if I use the bool function. For example: bool(1) #=> True Does such a construct exist in Ruby? I can't seem to find evidence ...
-1
votes
3answers
35 views

How to check existence of an ActiveRecord from a query without iterating?

I have a model Item with attributes attr1, attr2 and attr3. Given a collection of Item models (e.g. from Item.all), how would I check if there exists an item with attr1 == value1, attr2 == value2 ...
2
votes
0answers
28 views

How to ignore DST when parsing string to time (Time.parse) in Ruby

I need to parse strings with timestamps and convert them to Time objects. I am struggling to understand how Time.parse works and how to ignore DST and use always UTC or simply convert to UTC I keep ...
-2
votes
0answers
35 views

How to seed multiple items within same column?

I am trying to seed multiples items into the same column, i.e. 1 user with 5 products, but doesn't seem to work, I was wondering how do I do it? codes below User.create!([{ name: "Ant-Man", email:...
2
votes
0answers
35 views

How to resolve AWS problem route not found Nginx Ruby?

I'm trying to install my Ruby API on an AWS server, with nginx. And I have a problem that nginx can't find some of my roads (which works very well locally). But it finds the one that are present on ...
1
vote
1answer
36 views

Ruby On Rails: make text_field displaying the content from another text_field while editing

I am fresh of ruby on rails and have a question about how to display a input on multiple text_fields. For example, I have two textfields called name and path. While I type "Project" in name textfield, ...
1
vote
3answers
56 views

How to add spaces to any given string and maintain N chars?

In Ruby using regex, I want to modify a given string that will be shorter than or exactly 15 characters, so that it is always 15 characters by adding spaces. For example: 'apple' => 'apple(10 ...
0
votes
1answer
44 views

How to spy on a method called at class level on ActiveRecord model?

If I have a model module MyModule def bar(str) puts str end end MyModel < ActiveRecord::Base include MyModule bar('foo') end My spec: describe MyModel do before do ...
1
vote
2answers
48 views

How to fix a CSV read error with a semicolon at line end

I want to use Ruby's CSV class to read a file: The file to read looks like: CM_ SG_ 1325 XXX_Address "XXX address"; CM_ SG_ 612 YYY_MsgCounter "incremented by 1 each time a message has been ...

http://mssss.yulina-kosm.ru