Category "ruby-on-rails"

Why am I getting a nil value from a Ruby object's member, when it is not nil? [closed]

I want to get the value of a field (ScenarioID) in a Ruby ActivityChart object (chart). Displaying the whole chart shows the value I want: 16

React / Rails / I18next change language in URL or refresh server-side props

I'm using React with Rails. I get some props from a React controller when rendering the page initially. When changing the language on the frontend (I18next), we

Rails 5.2 load order breaks db:create

I have a rails application that on Rails 5.1 had no troubles creating MySQL db schemas but fails to create after upgrading to Rails 5.2. It seems like with 5.2

clean way to read out id in a request path in ruby on rails

I have a request that comes in like this: api/v1/photos/1/media/2 "1" and "2" are ids I need to read out in the controller. "2" I can get through the parameters

Login flow with Hotwire

I'm currently developing my first application with Rails and Hotwire. It includes a comment form visible to all users. When unauthenticated users submit it, I'd

How to use and load JS helpers in Stimulus controllers in Rails 7?

I want to import and use functions from my javascript/helpers/functions.js file in my stimulus controllers. I tried pinning it with: # importmap.rb pin_all_from

With RSpec, how do I write an expression that captures _spec files in nested directories?

I’m using Rails 6 with RSpec 3.10. I have the following directory structure spec/models/my_object_spec.rb spec/models/module_name/product_spec.rb I run

When using the friendly_id gem - can you ignore certain routes like /about /contact?

I'm using the friendly_id gem in a Rails application, to be able to view organisations at site.com/organisation-name The problem is that I have a few static pag

Attempting to register a user on my devise app causes undefined method `user_url' for #<Devise::RegistrationsController:0x00000000020ee0>

I am still getting this error when I'm trying to register new user, but I can log in to created user after refreshing page. Here is code which I'm getting on th

ActionController::UnknownFormat After Rails 7 Upgrade

I have a calculator which users would enter in values, hit submit and without refreshing or re-rendering, the calculated values would display on the page. All w

How to wait for all Concurrent::Promise in an array to finish/resolve

@some_instance_var = Concurrent::Hash.new (0...some.length).each do |idx| fetch_requests[idx] = Concurrent::Promise.execute do response = HTTP.get(EXTD

Load a turbo frame with a select OnChange event?

I have a nested form where the nested form items are conditional on the selections in the main form. I have the nested part of the form in a turbo frame. I ha

How do I ensure assets are present with Rail 7, cssbundling-rails, jsbundling-rails in test mode (RSpec)?

I'm upgrading a large, commercial (proprietary) Rails 6 application to Rails 7. We never used Webpacker, and are instead going directly from bundled gems for th

Rails app: I am having trouble creating joint instance

I want to create a simple app where admins can post their job offers and regular users can apply to those job offers. For that I have created a joint table: My

Unable to auto-format *.rb in setting.json below in VScode

I want to auto-format all html, css, sass, rb, and html.erb,js files with setting.json_Vs-code. But the next file after setting.json can only be the above *.rb

Ruby NoMethodError: undefined method

I am using rack-reducer with rails. I am getting the error: #<NoMethodError: undefined method 'order_from_user_input' for #<DataPoint::ActiveRecord_Relati

How to send a POST request with after create or update of a user (RAILS)

This is my first time working with Requests and i'm a little confused, any guidance would be greatly appreciated. Task: after a user is created i would like to

How to access nested attribute in Rails Sql

I have the following Alert object that looks like this: <Alert id:1, message: "{\"body\": "\This is a test.\"}" > I'm trying filter the body content f

How to search nested hash of arrays and arrays of hash and return multiple matching objects from the parent node?

Say I have the below ruby hash nested hash_or_array = [{ "book1" => "buyer1", "book2" => { "book21" => "buyer21", "book22" => ["buyer23", "b

How to capture record versions by PaperTrail on bulk insert in Ruby on Rails?

I use Paper Trail gem to capture versions of my models and it works very nicely. But Paper Trail don't capture version on bulk insert. Example: User.bulk_import