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

What is the difference between stub and stubs in Minitest?

At a glance, the documentation for .stubs refers back to .stub. However, the former seems to implement an API more akin to Minitest's mock. Also, .stub requires the stubbed method to exist while the ...
0
votes
1answer
28 views

Running Ruby in C

Im trying to run a block of Ruby code inside a C program. I have the following code: #include <ruby.h> int main(int argc, char* argv[]) { /* construct the VM */ ruby_init(); /* ...
0
votes
1answer
20 views

How to stub a ruby method ensuring that it exists in Minitest

Contrary to the documentation on .stubs, it seems that I'm able to stub a method that doesn't exist. Considering the following code: class DependencyClass def self.method_to_be_stubbed 'hello' ...
0
votes
1answer
19 views

Unitialized constant User:Bookings when trying to add data into a join table

I have a User table and a Booking Table that is linked by a create_join_table what holds the user id and booking ids. When a user books a room, i need the id of both the user and new booking to go ...
0
votes
0answers
11 views

How to fix incompatible library version error for Ruby on Rails on Ubuntu

Hi I tried use production console as rails c production for clean Rails cache (i.e. Rails.cache.clear); but I couldn't launch the console due to incompatible library version error for nokogiri. Full ...
0
votes
0answers
10 views

Re-Usable Components in Cheezy Page Object

I'm using cheezy page-object gem and cucumber. I have page objects for an angular website and many pages contain angular ng-select element which is a dropdown. All of the ng-select elements are the ...
0
votes
1answer
21 views

ArgumentError in EnvelopesController#index

i am trying to validate that amount in Account cannot be less than the sum of amount in envelope but i am getting this error You need to supply at least one validation validates :...
0
votes
0answers
13 views

Ruby Coverband - how to make sure it is not enabled?

I understand that I can set COVERBAND_DISABLE_AUTO_START to disable auto start. Is there a way to confirm that Coverband is indeed not running and taking system resource? I see there is a bug (https://...
0
votes
1answer
28 views

Rails: Difference between declaring a route directly inside the `resources` block vs. enclosing it with a `member` block

What's the difference between the /animals/:animal_id/info(.:format) and /animals/:id/info(.:format) routes in the following, except parameter names? And why are the parameter names different? config/...
0
votes
0answers
12 views

RSpec shared example for CRUD Controllers that might be nested or not

I've been trying to create a shared example to quickly and efficiently test controllers with CRUD operations that might also be nested. I came up with this solution that works, but I feel that it can ...
-4
votes
0answers
15 views

convert Java encryption/decryption to Ruby [closed]

I have snippet of code in Java responsible for Encryption and Decryption and need to convert in Ruby. Before posting here I gone through all ways but the result is entirely different.Please help to ...
0
votes
1answer
15 views

Rails nested form checkbox field not saving to my database model

I have a model association between two models Listing & Pricing. These are associated through Listing_Pricings model on a many to many basis. If a listing is created the user can select through ...
0
votes
1answer
19 views

I am getting an error on line 13. It says that the `<<` method is undefined. how do I fix this? I am using Ruby

This is the code: def self.scrape_shoe @doc.css("div.product-card__body").each do |nike| name = nike.css("div.product-card__title").text.strip price = nike.css("div.product-...
2
votes
1answer
25 views

Ruby: mixins, inheritance and constants name resolution

My program has following structure: module M1 class A def action C.new.foo end end class C def foo puts "M1::C foo" end end ...
0
votes
0answers
29 views

undefined method `[]' for nil:NilClass after adding an if statement

I am getting an NoMethodError after adding an if statement which throws an error if the number of digits entered by the user is greater than 5. If the duration filter is not selected and the user ...
0
votes
1answer
34 views

belongs_to and has_many in rails

I'm currently working in a project in which users can add users to a company, I want to save who added each user so there would be a belongs_to relation but one user can also add multiple users so ...
0
votes
0answers
17 views

How to check if my token is active ruby on rails

I would like to set my token only once per user, do you know how to check if my token is already set ? Here is my Controller : def connexion code = request.params[:code] @...
0
votes
0answers
28 views

How can i encrypt passwords in ruby on rails? [closed]

Hey guys I'm new on Ruby on Rails, I need to make a form for login and registration using RoR and for security reasons I can't store passwords without encryption, but I don't know how can I store ...
0
votes
1answer
24 views

undefined method 'size' for Stack in Ruby

I am trying to make a min stack function, but I think I don't understand something with the size of the loop, this is my code: class Node attr_accessor :value, :next_node def initialize(value, ...
-3
votes
0answers
19 views

Can someone help me on PUT please? Just missing this to complete MY CRUD. THANK YOU [closed]

I need to generate a put but I don't know how to pass the parameters to update the name, salary or age from Gem Faker. How to upgrade from GEM faker or any even fixed value!!? I tried but could not, ...
1
vote
2answers
27 views

How do I stack queries using Active record?

I want to stack or join multiple queries to the same model. For instance, I have these two queries: @query1 = User.where(:survey_response => params[:survey_response]) @query2 = User.where(:...
1
vote
0answers
26 views

Active Admin file app/admin/**.rb load take a lot of time

My Rails Project have 30 active admin file in app/admin/ . When I change some code and reload, Opening page take 6 second. Then I delete all file in app/admin/**.rb . Opening page take just 1 second. ...
1
vote
1answer
25 views

undefined method `each' for true:TrueClass (NoMethodError)

I'm writing a for loop in Ruby that iterates through the elements of an array until there are not more elements to read or a condition is met. This is my implementation: # 'all' is an array exists = ...
-1
votes
0answers
22 views

how to access attr_reader values in class method Ruby

I have this class and I am trying to do this class ShowPage < SitePrism::Page def initialize(site) @site = site end class << self attr_reader :url, :site ...
1
vote
1answer
25 views

How to invoke custom method in GraphQL::Schema

I am trying to add a check in GraphQL::Schema. I want to call a method where I have defined my schema. One Way is to call the method in GraphqlController. But, I am not able to get the arguments that ...
-3
votes
0answers
33 views

can you help me for spces for these controller in ruby on rails [closed]

class StudentsController < ApplicationController before_action :authenticate_user! def list @students = Student.all end def show @student = Student.find(params[:id]) ...
0
votes
1answer
48 views

How to modify string value in ruby?

I have two methods in my ruby class and I am trying to modify a local variable string on another method, def modify_test value = 'initial stringg' remove_last_char(value) puts value end ...
0
votes
2answers
42 views

Adding data into a middle table from two other tables in RoR

I have 3 tables that link with each other: User, Booking and User_Bookings. When the user books a room, I want it so the booking ID and User ID are submitted into the joining table so they can view ...
1
vote
0answers
53 views

Unable to interpolate an array with one more than one item into another array using %W

foo = %w[a b] # => ["a", "b"] bar = %W[bla baz #{foo}] # => ["bla", "baz", "[\"a\", \"b\"]"] In the above example, as you can see a and b are wrapped around escape strings, is there a way I can ...
0
votes
1answer
28 views

Jquery Validation REGEX always fail

Jquery validation always fail when correct regex, regex check to see if text in box matches the following format: YYYY-MM-DD. tried all the different ways I could find. Using the jquery-validation gem ...
0
votes
0answers
29 views

how respond_to? method works in rails

I came across code snippet something like this. attr_accessor :category, :search def run if respond_to?((category&.downcase).to_s, true) send(category.downcase) else send(:...
1
vote
1answer
16 views

Will `rvm install 2.6.3` install binary Ruby by default?

What's the difference between: rvm install 2.6.3 and rvm install 2.6.3 --binary Will rvm install 2.6.3 install binary Ruby by default if it can find one to save you from wasting time compiling ...
-2
votes
0answers
30 views

How to fix an “undefined method `title' for nil:NilClass (NoMethodError)” [closed]

I have run into an error and am absolutely stuck undefined method `title' for nil:NilClass (NoMethodError). I have tried to fix it and nothing seems to working towards a solution. I have tried ...
3
votes
2answers
56 views

CSV - Processing all the rows with same value at once [closed]

I have a large CSV file with the following headers "sku","year","color","price","discount","inventory","published_on","rate","demographic","tags" and I'd like to be able to process once at the time ...
0
votes
1answer
32 views

Rails create data in has_many :through relation

I have these file and a CSV file. Now I want to job.rb class Job < ApplicationRecord has_many :city_jobs has_many :cities, through: :city_jobs end city.rb class City < ApplicationRecord ...
-2
votes
1answer
17 views

View calendar if there is an event ruby on rails

I'm working on a site and was wondering if there was a way to check if there is an event. And if there is event then display calendar, otherwise hide the calendar? or even display an empty calendar? ...
0
votes
0answers
26 views

getting all repos in a Github api query

I have the following query hooked up to a rails app. It only seems to be returning 30 projects at a time, even with an increased per_page count. However, if I make the same request via the browser, ...
0
votes
2answers
40 views

querying a CSV::Table to find item with most sales between two given dates in plain old ruby script

I am trying to find the highest sales between two given dates. this is what my ad_report.csv file with headers: date,impressions,clicks,sales,ad_spend,keyword_id,asin 2017-06-19,4451,1006,608,24.87,...
-2
votes
1answer
22 views

Trigger ruby script when button is pressed [closed]

I'm working on an app where a user submits data, and that data gets stored into a variable and sent to an API database. From there that information is handled by the API and not the app, so there's no ...
2
votes
2answers
54 views

better way to get attributes if object is null

I am going to get first name. billing_address = { "first_name" => "Jack" "last_name" => "James" } billing_address["first_name"] But if billing_address = nil, it gets error. So I updated ...
1
vote
0answers
29 views

Added Timeout to method, and now the first spec always fails

I recently added a timeout to a method that is used by about a dozen different commands in the class. Here is the method: def exec_mc!(command) begin Timeout.timeout(30.minutes)...
0
votes
2answers
20 views

How to deal with a duplicate key from Faker in Ruby

How do I loop if Faker generates an existing name for the name field? The name field is the primary key in this table. When it finds a duplicate name it will generate until it finds a different name....
2
votes
1answer
18 views

Ruby - constant initialisation with some function produces NoMethodError

Let's consider following code: class Try CONST = xxx("42") private_class_method def self.xxx(str) str.to_i end end puts Try::CONST It produces an error: undefined method `xxx' for Try:Class (...
0
votes
1answer
21 views

Rails 6 Active Storage image_processing gem issue

Using Rails 6.0 and 'image_processing', '~> 1.9.3' When trying to show a cropped variant of an image with: url_for(user.avatar.variant(crop: crop_geometry)&.processed) I get an error: You ...
0
votes
1answer
28 views

How to use two versions of the same gem on the same ruby version in asdf?

I have switched from rvm to asdf and need a behaviour similar to gemsets in rvm. I have two folders with the same project - one with the old version of it and one with the latest one. They have the ...
2
votes
2answers
46 views

can make module name uppercase?

lib/modules/job/web.rb module Modules module JOB class Web def self.type end end end end I used - Modules::JOB::Web.type but I am getting this error - NameError: ...
0
votes
1answer
22 views

Undefined local variable or method `make' when installing therubyracer on MacOS

I've been developing on this project for about a year now, but about a month ago I ran into an issue where I had a gem installed that was incompatible with my version of ruby (using rbenv; 2.3.1). I ...
0
votes
1answer
31 views

Some hook after initialization of ruby class?

For example I have some class with this initialization: class SomeClass < ActiveRecord call_some_method('bla_bla_bla') def some_method return 1 end # end of initialization or ...
0
votes
1answer
26 views

Can someone tell me how to load different assets folder instead of normal assets

I am working on a Rails project where we need to use different assets folder but I am not able to figure it out how is that possible. By default rails load assets folder and in my case, I have to load ...
0
votes
2answers
22 views

Ruby: script to convert structured text to a csv

I have a text file with structured text which I wish to convert to a csv file. The file looks something like: name: Seamus address: 123 Strand Avenue name: Seana address: 126 Strand Avenue I ...