Category "ruby"

Navigate to Ruby function definition in VS Code

I'm pretty new to Visual Studio Code, and I'm trying to edit some Ruby code. I installed Ruby support, and I enabled the language server, but Ctrl-clicking on a

Convert Hash to OpenStruct recursively

Given I have this hash: h = { a: 'a', b: 'b', c: { d: 'd', e: 'e'} } And I convert to OpenStruct: o = OpenStruct.new(h) => #<OpenStruct a="a", b="b"

is there a way to set after_commit callbacks to a specific ActiveRecord transaction

I am creating a ActiveRecord transaction this way ActiveRecord::Base.transaction do MyModel.create!(name: "value") OtherModel.create!(name: "value") end

Bundler could not find compatible versions for gem "bundler":

Complete new person to Ruby and Rails here... Have tried some tutorials in the past, but that's about it. I'm trying to follow 'Ruby on Rails 3 Tutorial' book

Failed to build gem native extension: Unable to install Rails + MySQL2

I am on MAC OS X LION and keep getting error message Failed to build gem native extension when trying to install rails and mysql. This is what I am doing. I en

How do I dynamically add my Ngrok tunnel to config.hosts in Rails 6?

I'm trying to whitelist my ngrok tunnel hostname in config.hosts but it changes every time I start Ngrok. Is there a way to get the public url of my Ngrok tunne

How to detect if two images are the same with different cropping ratios?

I have two different images with different dimensions: 100px and 400px As you can see the two are clearly the "same" from a human point of view. Now I wanna

Other Ruby Map Shorthand Notation

I am aware of the shorthand for map that looks like: [1, 2, 3, 4].map(&:to_s) > ["1", "2", "3", "4"] I was told this is shorthand for: [1, 2, 3, 4].m

Use if statement in layout.html.erb in a Sinatra app

Within my Sinatra application I would like to serve a minified version of my css/js for production but in development keep my default setup (individual files).

-bash: /Users/myname/.bash_profile: Permission denied

I installed rvm (ruby version manager) and it was success, but I got WARNING: You have '~/.profile' file, you might want to load it, to do that add the fo

What is the send() method used for?

Could someone please help me to understand what the 'send()' method listed below is used for? The code below, when I am reading it, makes no sense what purpose

Redis increment only if < certain number?

How do I call .incr on a key and have it increment ONLY if the resulting number is < than a certain number without having to call .get beforehand? The reaso

How can I resolve sorbet error: "Constants must have type annotations with T.let when specifying # typed: strict"?

This is similar to my question in How can I resolve sorbet error: "Use of undeclared variable"?, but for constants. I am experimenting with adding sorbet type i

An error occurred while installing unf_ext (0.0.7.2), and Bundler cannot continue

I was trying to install diaspora into localhost. I removed the Gemfile.lock file and tried bundle install and am seeing this. These are the things I already tr

How can I resolve sorbet error: "Constants must have type annotations with T.let when specifying # typed: strict"?

This is similar to my question in How can I resolve sorbet error: "Use of undeclared variable"?, but for constants. I am experimenting with adding sorbet type i

Disabling irb autocomplete on Heroku

A follow up to Disable irb autocomplete I would like to disable IRB on Heroku, e.g. having an .irbrc with: IRB.conf[:USE_AUTOCOMPLETE] = false In the home dire

ROR + Unable to install tiny_tds

Here I am trying to fetch data from MS-SQL Server 2008 to my Rails application on Ubuntu 10. But I am unable to install tiny_tds. I follow the step given at git

Cannot install Ruby gem libxslt-ruby on Mac cause it does not find libxml2

I've installed libxml2 and libxslt through Brew on my Mac but gem install libxslt-ruby -- --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/op

How do I loop through XML using Nokogiri to add certain parts to an array?

I have this as my XML: <systems> <system number="2" > <lists> <list critical="user" access="remote"></list> <

How to set env variables using ASDF in a Rails project

Rbenv uses rbenv-vars to specify per-application environment variables in Rails. Most version managers read the .env file in every project for the environment