How to include or not include Rails module based on condition?
In my Ruby on Rails app I have this model:class Car < ApplicationRecord attr_accessor :name, :brand, :origin_country module ShippingCostCalculatorForJapan def calculate # Details left out for...
View ArticleHow to create a form in Rails with a variable number of jsonb items?
I have a model that stores modifiers for each year, for a variable number of years. It might be 0, it might be 10, it could be 50. The modifiers are not the same, and require different details...
View ArticleWhere does RubyMine find ruby versions?
Where does RubyMine find the versions of ruby to use on MacOS (Arm64 chip)?I use rbenv for version management. The ONLY version of ruby I have installed on my machine right now is 3.3.1.However,...
View ArticleHow to make Google Stackdriver works with Rails 7.1+
I just spent a few hours looking over the internet to find out how to resolve that issue. But, for the life of me, I have no idea what to do...I followed the documentation provided by Google...
View ArticleCheck if record was just destroyed in rails
So there is record.new_record?To check if something is newI need to check if something is on it's way out.record = some_magicrecord.destroyrecord.is_destroyed? # => trueSomething like that. I know...
View ArticleInclude module into method ruby
I have used module to extend class functionality. But suddenly I wonder if it is ok if I include a module directly into a method of the class instead of into the class like this:Original...
View ArticleWhat's the point of threads if ruby has GIL and can only execute one thread...
I read this about ruby:"If one of these threads wants to execute some Ruby code, it will have to acquire this lock. One, and only one, thread can hold the lock at any given time. While one thread holds...
View ArticleGetting Error - ActionController::UnknownFormat in...
Input ImageI'm encountering a "406 Not Acceptable" error in my Stimulus controller's fetch request. The controller is responsible for making an AJAX call to an endpoint, but it seems the server is...
View Articlebundler: failed to load command: rake (/opt/jruby/bin/rake) while running in...
FROM jruby:9.3RUN bundle config --global frozen 1WORKDIR /usr/src/appCOPY .bundle/config /usr/local/bundle/COPY Gemfile Gemfile.lock ./RUN bundle installRUN rm /usr/local/bundle/configCOPY . .CMD...
View ArticleWhere does `respond_to do |format|` come from when scaffolding a Rails...
When doing rails generate scaffold Banana, bananas_controller.rb has the following code: # POST /bananas or /bananas.json def create @banana = Banana.new(banana_params) respond_to do |format| if...
View ArticleRails - Foreign Key Constraint Failure For Belongs To-Has Many Relationship
class Appointment < ApplicationRecord belongs_to :teacher belongs_to :studentendclass Teacher < User has_many :appointmentsendclass Student < User has_many :appointmentsendclass User <...
View ArticleHow to loop 2D array in a anti-clock wise fashion?
Given a 2D array of m x n dimension, how can I loop through them in anti-clockwise fashion?For example:matrix = [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ], [ 13, 14, 15, 16 ]]1st loop: 1, 5,...
View ArticleHow to change Shopify tax calculation to use the billing address instead of...
I am trying to adjust the tax calculation in my Shopify shop so that it is based on the customer's billing address and not their shipping address. I have tried modifying the Liquid templates, but it...
View ArticleRails app not updating page when in responsive mode
I have an app built using Ruby 3.3, Rails 7 with import map and dart-sass for my asset-pipeline, the application uses bootstrap for css and coreui\coreui-admin as FE template.Saying that my error is...
View ArticleRails Routing - 'api/v1/sessions' is not a supported controller name [closed]
Rails.application.routes.draw do namespace :api do namespace :v1 do resources :users, only: [:create, :show, :index] post '/login', to: 'sessions:#create' delete '/logout', to: 'sessions#destroy' get...
View ArticleCan we method chain on lists?
I come from Ruby and you can method chain very easily. Let's look at an example. If I want to select all even nums from a list and add 5 to it. I would do something like this in Ruby.nums =...
View ArticleHow can I view list of permitted params using Rails strong_parameters?
I'm in the process of migrating from a Rails 3 application up to Rails 4 and making the changes to strong parameters. During this process I've been doing some command line debugging and would like to...
View ArticleHave you successfully used Sequel as an ORD with Snowflake?
I'm building a RoR application that will extract data from Snowflake and serve it via a REST endpoint. I have successfully connected to the Snowflake data source to get the data that I need and extract...
View Articleruby multi-stage docker build rails was resolved to 7.1.3.3, which depends on...
I am writing a multi-stage docker build but I am getting this errorIn Gemfile: rails was resolved to 7.1.3.3, which depends on actioncable was resolved to 7.1.3.3, which depends on actionpack was...
View ArticleStop Rails IRB and debugger sharing history
Since I moved to Rails 7.1 and Ruby 3, I am struggling to use the Rails console history.Previously, the console kept its own history, and the debugger history was separate. So if I was debugging a...
View Article