Questions tagged [ruby]
Ruby is a multi-platform open-source, dynamic object-oriented interpreted language. 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].
ruby
229,186
questions
-1
votes
0
answers
34
views
Why is the data in a Rails view displaying as 0.0 or 42.0 instead of $42.00?
Question Title: Why is the data in a Rails view displaying as 0.0 or 42.0 instead of $42.00?
Summary: How can I get this field to display e.g. $42.00 instead of 0.0 or 42.0? In addition to the ...
0
votes
0
answers
16
views
Issue with Psych::DisallowedClass Exception when using reify in PaperTrail with Sinatra
I am working on a Ruby project using Sinatra version 3.0.6 and Ruby version 3.0.0. I am using the PaperTrail gem (version 15.1.0) to track changes in my models for auditing and version control ...
0
votes
0
answers
38
views
Ruby case examples, consistently only shows one action under when [closed]
I've waded through multitudes of Ruby case questions, here and on the web. They all have one thing in common, they only show one statement following the when. Of the form,
case whatever, simple, ...
1
vote
1
answer
49
views
Ruby module is not an ancestor after prepend
I'm developing a plugin to the Rails (6.1.7) project Foreman (v3.5.1; based on the Foreman Plugin Template) and face the issue that one of my modules (DnsInterfaceExtensions) ought to be prepended to ...
0
votes
0
answers
37
views
How can I fix Postgres errors in Minitest?
I am using Minitest and Postgres to test my Rails website. When I added a "Like" model, I started getting Postgresql deadlock errors
Minitest::UnexpectedError: ActiveRecord::Deadlocked: PG::...
0
votes
0
answers
154
views
Can I download a old version of google chrome stable? [closed]
I use the below config file in the .ebextensions to preinstall the Google Chrome stable when deploying our Ruby application to AWS EB.
commands:
01-install:
command: rpm -q google-chrome-...
0
votes
0
answers
27
views
Issue with 'libgmp-10.dll' in Ruby while compaling script with Ocra
I'm having an issue while trying to create an executable with ocra in Ruby and I'm not able to fix it no matter what, even chatGPT couldn't help.
The issue is with libgmp-10.dll. The compiler works ...
0
votes
0
answers
31
views
finding the appropriate session for an IdP single logout request with Ruby SAML
I'm putting together a gem for our Rails apps to use SAML single sign-on/logout via Entra ID. I had some questions about the final bit I need to implement: ID provider initiated single logout requests....
1
vote
1
answer
92
views
How to set view context in Rails?
I’m building a gem that intercepts Rails’ default render behavior. Instead of rendering a view, it looks for a helper method that corresponds to the current controller’s action name; it then uses the ...
0
votes
0
answers
33
views
How to remap exceptions with Grape?
In a Ruby project using Grape, I have a custom exception Api::Exceptions::InvalidValueError that subclasses Grape::Exceptions::Base. If a validation fails (which causes Grape::Exceptions::...
0
votes
2
answers
74
views
How can I update how ActiveRecord::Base#where interprets ranges?
It appears that ActiveRecord::Base#where partially distinguishes between ranges defined with 2 dots (0..) and ranges defined with 3 dots (0...).
E.g.
> User.where(id: ..0).to_sql
=> "SELECT ...
0
votes
3
answers
66
views
authentication from scartch in rails
Hi i am learning rails from the Odin project and i am creating a simple authentication without using devise . the course doesn't really give enough info to help beginners finish that project
so, Here ...
1
vote
1
answer
42
views
Rails form_with-helper: What is a :scope?
I'm currently reading the Ruby on Raily API-documentation. Specific the part about the form_with helper: https://api.rubyonrails.org/v5.1.7/classes/ActionView/Helpers/FormHelper.html#method-i-...
1
vote
5
answers
156
views
In Ruby, how do I find a value in an array of hashes?
I am trying to get a value in an array of hashes in Ruby. Given the following information below:
# array_of_hash_objects will look something like this:
# [
# { name: 'Ruby', is_my_favorite?: ...
0
votes
1
answer
86
views
Rails 7 error during application start - Zeitwerk-related errors
I'm upgrading my rails app from 6.1 to 7.0 and i'm running into this runtime error:
I do use the Authlogic gem, but the odd thing is i have no config/initializers file for Authlogic, and i can't find ...
0
votes
1
answer
35
views
Injecting dynamic values for a specific schema to validate against
I have the following yaml file that I would like to validate using dry-rb.
---
environment: # required
test: # should be dynamic
service_credentials: "test_credentials" # required
...
1
vote
1
answer
64
views
How to automatically derive foreign key column names with polymorphic associations?
In my Ruby on Rails 7 application I have a large Account model with various has_many associations (most of them are left out for brevity here):
class Account < ApplicationRecord
has_one :...
0
votes
1
answer
32
views
xapian-full-1.2.3 not able to install succesffully
Application not starting after ubutu patch upgrade.
/home/azureuser/app2/current
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent ...
-1
votes
0
answers
26
views
Implement prometheus and garafana for a ruby on rails application [closed]
I am looking for a help to implement prometheus and garafana in my rails app. I have tried using prometheus-client and yabeda-prometheus gem. I have also tried with prometheus-exporter gem but all in ...
0
votes
1
answer
98
views
Native file open dialog in Windows Ruby
As far as I understand, there are no gems which help to open native file dialogs, so I am interested in writing one, specifically for Windows
I'm stuck at the first step which is getting the CLSID for ...
0
votes
0
answers
75
views
Ruby (3.3.4) and Rails (7.1) - rails s Zeitwerk - uninitialized constant Utils::ScriptsUtils::Utils (NameError)
I am trying to update my ruby app from ruby 2.6.6 to ruby 3.3.4 and Rail 5.1 to Rails 7.1
I know it is not a good practice to do so, but in my case (which is a bit complicated) I felt I didn't have ...
0
votes
1
answer
33
views
Installing Jekyll on my M3 Macbook won't "stick"
I think I have painted myself into a corner trying to override the default Ruby install so that I can install Jekyll.
Here is a rough timeline:
I follow this tutorial to the letter and it works, my ...
0
votes
1
answer
51
views
Ruby on Rails: how to efficiently save nested attributes (recursively)?
I'm using Rails 6.1.3.2 and trying to make saving of nested attributes more efficient. The database used is MySQL.
Code basis
BoardSet.rb
class BoardSet < ApplicationRecord
has_many :boards, ...
-1
votes
1
answer
39
views
Exception: <internal:/usr/local/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
Exception: <internal:/usr/local/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require': cannot load such file -- xcodeproj (LoadError)
from <internal:/usr/...
0
votes
1
answer
63
views
How do I make sure that I only load flights on search and not initial page load
Rails baby here! trying to work it out with Rails 7. I have a small toy app here that tries to search for flights then have users book a flight. I have managed to string together the app to a point of ...
2
votes
2
answers
69
views
How can I get commands in Rails Migration file using regex?
I'm trying to get commands from a Rails migration file as an array based on a specific migration command, using regex. My code works well on most cases, but when there is a command with multiline code,...
1
vote
1
answer
55
views
Rails: Form that sets up default values for an object?
Say I have an object that has some attributes with default values. I set up the default values for these attributes at a model level like so...
after_initialize :set_defaults
def set_defaults
...
1
vote
0
answers
29
views
Trouble Configuring SAML Authentication in Rails with Devise: Signature Verification Failure
I am currently integrating SAML authentication into a Ruby on Rails application using the Devise SAML Authenticatable gem, and I've encountered a significant challenge regarding the signature ...
0
votes
2
answers
57
views
How to configure Rubocop to skip counting log lines - Metrics/MethodLength AllowedPatterns/AllowedMethods
Running RuboCop results in the following error
$ rubocop
Running RuboCop...
Offenses:
C: Metrics/MethodLength: Method has too many lines. [25/10] (https://rubystyle.guide#short-methods)
def ...
1
vote
1
answer
30
views
Rails Cookies not updating on other pages
Is there a way in Rails to delete/reset a particular cookie when the value has been changed on one page?
So I have 10 tabs, if the cookie is changed on tab 1 it doesn't update on the rest of the tabs ...
0
votes
0
answers
18
views
Rails Shrine with Uppy can't perform direct uploads
Trying to integrate uppy on my rails app. I'm using rails 7 minimal version with Shrine gem.
I'm able to upload to s3 but as i try to integrate uppy it just fails.
I get errors in browser console and ...
0
votes
0
answers
33
views
Extract which bytes should be included in the hash calculation (Signature)
I'm looking to implement the enveloped signature in a project and I'm creating a proof of concept.
The integration documentation requests that:
Prepare the signature document
Calculate which bytes (...
-1
votes
1
answer
47
views
How to avoid sql injection warning for rails scope [closed]
I have written scope on modal as below and called ruby class method 'display_link_query'
scope :data, -> { select("id,#{display_link_query} as display_link
.references( :...
-1
votes
1
answer
52
views
print function info without repeating or explicit calling a function in ruby
For debugging propose, in each method there is a print of the function namespace and its argument
module Test
def self.foo(arg1, arg2)
args = method(__method__).parameters.to_h { |p| [p.last, ...
1
vote
1
answer
79
views
App not starting with cryptic Passenger log error
I have a Rails app set up with Passenger + Nginx.
When trying to access the app I get the following error in passenger's logs:
/home/my_user/.rbenv/versions/3.3.1/bin/ruby: No such file or directory --...
0
votes
0
answers
82
views
What is best way to set time in a Rails app form so that the time is the same once I enter it and doesn't change?
I have a Rails 7 form where I enter in data to populate a database. I have a start_time and end_time in the form:
<%= f.time_select :start_time, :value => Time.now.strftime('%I:%M %p') %>
<...
3
votes
2
answers
72
views
Rails: How does form_with know, which Controller-action to invoke?
Taken this form as an example:
<%= form_with model: @product do |f| %>
<!-- ... --!>
<% end %>
The routes-file:
get "/products", to: "products#index"
get &...
-1
votes
0
answers
40
views
How to handle session managment in ruby on rails app with mixed structure monolithic and api using devise and devise jwt
I have a Ruby on Rails 7 app with devise to handle Registration and session managment for 3 models, Admin, Company and Users. Company has_many users, Admin and Company works in the monolithic ...
0
votes
0
answers
42
views
How to download Sidekiq Pro (private gem) in pipeline
Sidekiq Pro is a private Ruby gem that requires authorization and, although I've gotten it to work locally, I've been unable to get it to work in the pipeline. I use a yaml file on my repo to define ...
0
votes
0
answers
43
views
Heroku : ruby app, issue when i tried to push it
i create an app on ruby on rails with heroku
this app already exist online
now I try to push a new version of this one on heroku, but i have an issue.
i already update my ruby and rails version (...
0
votes
1
answer
47
views
Model method not recognizing parameters
I'm building a rails app where users can search through "Playlists", which is an object containing a title, image, and tracks.
I've defined a search method in the Playlist model that takes ...
1
vote
1
answer
55
views
Saving an associated polymorphic object duplicates it
I have two models, one of them being polymorphic and second one being a "parent" one:
class Person
has_one :asset, as: :assetable
accepts_nested_attributes_for :asset
end
class Asset
...
0
votes
0
answers
76
views
For Ruby extension, how should I save a reference in C or Rust side?
I'm working on a client-side caching library that caches objects in a HashMap.
A simple example is below:
fn insert(key: RString, obj: AnyObject) -> AnyObject {
let rust_struct = self....
0
votes
0
answers
20
views
Can't activate jar-dependencies-0.3.10, already activated jar-dependencies-0.4.1
I'm getting this error.
can't activate jar-dependencies-0.3.10, already activated jar-dependencies-0.4.1
Please help me
My project has gem 'jar-dependencies', '0.4.1' but in my system it was ...
1
vote
1
answer
57
views
Ternary operator not working inside Lambda function Ruby
I am trying to write a Lambda function in Ruby, to calculate the nth Fibonacci number.
fib = -> (n) { n in [1, 2] ? 1 : fib.[n - 1] + fib.[n - 2] }
This gives me the error,
./fib.rb:3: warning: ...
0
votes
1
answer
47
views
Rails: Extended class that calls another extended class
Setup:
We got an initializer (in config/initializers) that requires a file where we define our extensions.
This file does something like this:
module UbiquoExtensions
end
:SomeClass.include!(...
0
votes
1
answer
75
views
bundle install cannot load such file
When I try bundle install or RCT_NEW_ARCH_ENABLED=1 bundle exec pod install in my project I get this error. Mac on chip M2
/opt/homebrew/opt/ruby/bin/bundle:25:in `load': cannot load such file -- /opt/...
2
votes
1
answer
64
views
Ruby setter-methods: Is the equal-character (=) a convention or functionality?
Taken this class as a example:
class House
def initialize(color, size)
@color = color
@size = size
end
def color
@color
end
# Is the = part of the syntax or a convention?
def ...
0
votes
0
answers
29
views
Trying to install Nanoc (with Ruby) on Fedora Linux, but getting an error I can't decipher
I try to install Nanoc on Fedora Linux.
I've successfully installed Ruby using
dnf install ruby
Checked it with ruby -v and made sure rubygems is installed. Also checked version to verify ...
0
votes
0
answers
18
views
Issue with rails hotwire trix textarea resize
im trying to create a textarea resize grippie more or less like the SO for a trix textarea with rais stimulus so i set this controller below
the issue is when i pull down the textarea the textarea ...