Questions tagged [ruby-on-rails-7]
For Ruby on Rails 7 questions: Ruby on Rails 7 is a web app framework in Ruby. Use tags like [ruby-on-rails], [ruby], [rails-7], [activerecord], [actionview], [actioncontroller], [routing], [authentication], [authorization], [database], [testing], [deployment], [gems], [api], etc. Provide specific details and errors.
ruby-on-rails-7
965
questions
-1
votes
0
answers
18
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 ...
1
vote
0
answers
30
views
Rails 7.1 Turbo stream not working on localhost, but works when deployed to Heroku
I have a very simple Rails 7.1.3.4 app that is essentially a dashboard, where it uses Turbo Streams to display model attributes in real-time. When I deploy my app to Heroku, everything works as ...
0
votes
0
answers
25
views
localhost:3000 not working when I start a docker container for my Rails project
I was following a tutorial on how to Dockerize a brand new Rails 7 app. I made the Docker container 'distant-mirror' Setting up the Docker container took about two hours, but now I entered in my ...
0
votes
0
answers
47
views
How to delete cookies in Rails 7.1?
I recently upgraded my Rails app from version 7.0.4.3 to version 7.1.3.4 and cookies.delete stopped working.
I'm setting a cookie in JavaScript with:
document.cookie = `last_guess=value; path=/`;
...
1
vote
0
answers
33
views
Failed to resolve module specifier "application" .Unable to load the application.js file in rails engine
Uncaught TypeError: Failed to resolve module specifier "application". Relative references must start with either "/", "./", or "../".
In rails 7 while creating ...
1
vote
1
answer
81
views
ActiveRecord::NotNullViolation: RuntimeError: NOT NULL constraint failed: drives.created_at
I am using latest ruby 3.3.3 and latest rails 7.1.3.4.
I am new to rails and I am learning it. Sorry if my request seems dumb to some.
I got this error when I run tests.
It seems that ActiveRecord is ...
0
votes
1
answer
72
views
Rails 7: Psql trying to connect to the wrong database but trying to create correct database
In production mode, I am testing connecting a rails 7 project to a remote server for the postgresql database. However when I try to connect to it, it starts looking to connect to the postgres database ...
0
votes
0
answers
35
views
How do you make Javascript work in rails engine?
I have added these gems in Gemfile
gem "sprockets-rails"
gem "importmap-rails"
gem 'stimulus-rails', '~> 1.2', '>= 1.2.1'
gem 'hotwire-rails', '~> 0.1.0'
gem 'turbo-rails',...
1
vote
1
answer
82
views
Paste multi lines in Rails console with pry
Problem: I cannot paste multi-line code as pry tries to execute every line.
Expected behavior:
[1] pry(main)> %w[a b c]
.map(&:to_sym)
=> [:a, :b, :c]
[2] pry(main)>
Actual behavior:
[1] ...
2
votes
1
answer
71
views
Why would `has_secure_password` suppress password validation on update, but only if the object is newly created?
Let's say I have a simple model like so with a presence validation on the password field.
class User < ApplicationRecord
validates :password, presence: true
end
If I try to update the password ...
0
votes
0
answers
51
views
Debugging tailwindcss:watch in Procfile.dev in Docker
I am trying to build a development compose.yaml to mimic what I hope to be my production deployment. Currently it looks like the following using bin/dev.
services:
web:
build:
context: ./
...
0
votes
0
answers
76
views
Use custom fonts Rails 7 with jsbundling (esbuild)
How to properly use custom fonts in Rails 7 with jsbundling? I'm trying to use Fontawesome-Free and Font Lora, but I'm getting a loader error.
13:46:30 web.1 | ActionController::RoutingError (No ...
1
vote
1
answer
51
views
Rails 7.1 Stack level too deep in partials and simpleform
After upgrading our rails stack from 7.0 to 7.1 i noticed these weird errors of stack level too deep even without much of a stack trace. It happens as far as i noticed, only whenever i have a simple ...
1
vote
1
answer
26
views
Sprockets::Rails::Helper::AssetNotPrecompiledError in MyEngine::Frontend#new
Asset hero_banner.jpg was not declared to be precompiled in production.
Declare links to your assets in app/assets/config/manifest.js.
//= link hero_banner.jpg
Rails.application.config.assets.paths &...
1
vote
2
answers
77
views
error trying to import module pinned in import map
I have a rails 7 app and I'm trying to add hotwire functionality. I am getting an error with pinning stimulus and importing it in application.js
importmap.rb
pin "application"
pin "@...
0
votes
0
answers
56
views
javascript_importmap_tags is creating a link to "application.js" with error
I am working on adding javascript handling to a rails 7 app. I want to use import maps to import external libraries for turbo and stimulus. The current issue I'm having trouble with is that ...
1
vote
1
answer
97
views
JS file is blocked due to bad MIME in production
In my Rails 7 project I have been using importmap for importing JS modules. here is the config:
# config/importmap
pin "application", preload: true
pin "@hotwired/turbo-rails", to:...
1
vote
1
answer
33
views
Rails controller doesn’t render any templates
I have a question about a rails 7 project I’m starting. I have a controller HomeController with one action home.
class HomeController < ApplicationController
def home
render
end
end
I have ...
0
votes
1
answer
15
views
Is there any way to set individual session timeouts using cookie_store in Rails 7 + Devise, or do I have to use a active_record_store approach?
I'm using Devise with Rails 7.1.3. I'm trying to implement a user configurable timeout value for session expiration, so for example Alice could set her expiration time to 12 hours and Bob could set ...
2
votes
1
answer
53
views
Rails: Validation-errors on object are gone after render :new
I have implemented following validation on my model-class:
class Department < ApplicationRecord
has_many :employees, dependent: :destroy
validates :name, presence: true, length: { minimum: 3, ...
-3
votes
1
answer
57
views
DEVISE NoMethodError in Admin::Shop#index (rails 7)
my apologies for all the pictures
I am following a tutorial by Conner Jensen(youtube) on creating an ecommerce platform using rails 7. I have run into a couple of problems whilst following this ...
0
votes
1
answer
49
views
Rails 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 ...
0
votes
0
answers
33
views
Adding new files in Rails engine's lookup context
I am making a rails engine which has a themes folder , in app/apps/themes . When you install the gem in a host application , the user should have the ability to add a new theme depending on their ...
0
votes
1
answer
58
views
Unicorn 500 code app error: undefined method `=~' for [...]:Array (NoMethodError)
Once again production deploying a rails app which is exciting. This time a Rails 7.1 app following the same guide I have before by Ralf Ebert Ruby on Rails – Deployment Tutorial. My setup is all good ...
1
vote
1
answer
58
views
Ruby On Rails - Turn If Else Statement Wiith Match? To Case Statement
How do I turn the following if / else statement:
if /_?town$/.match? name
['Springfield', 'Shelbyville', 'Kent', 'Carter', 'Benson'].sample
elsif /_?state$/.match? name
['TX'].sample
...
0
votes
1
answer
43
views
Error loading .rb file in /lib after migration from rails 3 to rails 7
I have a very old application written with rails 3 and need to update it to current rails 7.
I am stuck with a strange problem: in lib/assets there is a file tools.rb full of functions used across ...
1
vote
2
answers
69
views
Rails Associated Child Model
I am trying to follow the rails getting started guide to set up my project, but am running into an issue with setting up the nested models/controllers/views.
I have Activity model and Refusal model, ...
1
vote
1
answer
59
views
MyEngine::FrontendController#index is missing a template for request formats: text/html render different layout from controller
Layouts are present in app/apps/themes/default_theme/views/layouts
I have a frontend controller that renders layouts of different themes based on params. For now , lets assume it renders default_theme....
0
votes
1
answer
59
views
Rails 7 deploy failing on Render.com during assets:precompile - ActionView::Template::Error (The asset __ is not present in the asset pipeline.)
This bug is suddenly affecting all of our 3 Rails applications on Render.com. The codebase wasn't changed but the deployment suddenly stopped being successful.
During the build on Render.com, ...
2
votes
1
answer
77
views
DEVISE localhost:3000/admins/sign_in link always redirects to localhost:3000 (rails 7)
I am building an app in Ruby on Rails 7 that has Admin and User side. after configuring Devise, all of my Devise routes redirect to "home#index". how can I fix this? I inititially thought it ...
1
vote
1
answer
64
views
Rails Exception No Such Table Exists
I used rails generate to scaffold a ProjectType table and a ProjectGroup table that references project type. I created a project type successfully through the browser, but when trying to create the ...
0
votes
1
answer
99
views
Pagy gem: best practice to paginate a collection that comes from the model's has_many association
In my Rails 7.1 app I have two models: Movie and Director coupled together with the many-to-many association, so I can call e.g. Director.all[index].movies to get all movies associated with this ...
1
vote
1
answer
96
views
Search Rails 7 ActiveStorage filename with Ransack
I have a Rails 7.1.3 app that has ActiveStorage and Ransack installed. I have a model called Upload that has_one_attached :file. I would like to search by filename, using Ransack, in the uploads/index ...
0
votes
1
answer
42
views
Rails 7: Downloadable files in folders outside project folder
I am working on a project in which users can create PDF files and then download them.
Currently, I am creating these PDFs inside "public/" folder in the project.
But, I want to change the ...
1
vote
0
answers
56
views
Javascript error running Rails 7 app on IOS iPhone/iPad
We have an app build in Rails 7 with a Postgres database and uses Bootstrap 5 for the UI components. Pretty basic but effective app.
The app works fine on Windows and Mac browsers and on most Android ...
0
votes
0
answers
43
views
Rails JavaScript works fine only with direct URL
In my application I use javascript to manage the fields in the form. When I visit the website by entering the address directly in the browser eg http://IP:3000/admin/systems/new, the javascript ...
0
votes
0
answers
47
views
How to create records via FactoryBot with microservice app
I'm new to microservices, always worked with monoliths. I have an application with microservice architecture. The database is located in the part of app in a gem and is accessed through:
...
0
votes
0
answers
77
views
Getting "No loader is configured for ".svg" files" while adding custom plugins in ckeditor5
I am using @ckeditor/ckeditor5-build-classic in my Rails 7 application without webpack configuration.
the Classic Editor is working fine, but when I use the plugins (like: @ckeditor/ckeditor5-source-...
0
votes
1
answer
17
views
Blocking the possibility of logging in if the user is not in the database - Rails Devise
I'm using Devise and devise_ldap_authenticatable to allow users to login. I'm using only session controller
class Users::SessionsController < Devise::SessionsController
layout 'landing'
...
0
votes
1
answer
48
views
default session expiry issue on Rails
I have an application running in production mode. After a while, the session data seems to clear out. Currently I am using vanilla Rails 7.1.1.
What could be causing this? I want session data to stick ...
0
votes
2
answers
56
views
Rails 7: How to include a nested assosiation in a jsonapi-serializer
I have an author that has many books and a book that belongs to an author in an rails 7 api. I am using "jsonapi-serializer", "~> 2.2" to try and get the author and their books. ...
1
vote
1
answer
247
views
Getting bootsnap error when using 3.3.1 ruby versions
I am updating ruby version from 3.0.6 to 3.3.1 and bundle run successfully but when try to run rails server or rails c ,getting this error
**"**ArgumentError: comparison of String with nil failed ...
-1
votes
1
answer
75
views
Rspec on Docker with database_cleaner causes remote URL error: RemoteDatabaseUrl
I'm working in Docker, trying to run bundle exec rspec ./spec/services/something/something_spec.rb and I am getting this error
DatabaseCleaner::Safeguard::Error::RemoteDatabaseUrl:
ENV['DATABASE_URL'] ...
0
votes
1
answer
33
views
rollback database in local doesn't update postgres in server Rails 7
I'm running Rails 7 on my server, even though when I add a new table, it does migrate and I can see it in the server database. But when I made changes by rolling back in development environment, and ...
1
vote
0
answers
98
views
Getting randomly PG::Error: can't open large object with rails application
I have a rails application using postgresql 16, i am using latest version 1.5.6 of pg gem.
I have the below method:-
def file_length
transaction do
lo = active_connection.lo_open(self.oid, ...
1
vote
0
answers
42
views
Rails Gems that use JS not loading when navigating with Turbo in Production
I have a Rails 7 app using Turbo and ESBuild.
Some of my Gems (Recaptcha, Chartkick etc) also have a JS component. While on my localhost everything works fine, after uploading to Heroku the charts and ...
2
votes
2
answers
101
views
Rails: nested namespace produces a weird path to a partial, resulting a MissingTemplate error
I have an ActiveRecord model named Book, and a model named Book::Author. An author has many books through the Book::Authorship model (one-to-many association).
Off-topic:
In my app only ...
1
vote
1
answer
201
views
Understanding StimulusJS connect() vs initialize() in context of turbo/hotwire
The Stimulus handbook describes the difference between connect/initialize as:
initialize(): Invoked only once, when the controller is first instantiated
connect(): Invoked anytime the controller is ...
0
votes
0
answers
72
views
Configuring flatpickr in Rails7 using simple_form
I'm trying to add to my app date-time picker using flatpickr and simple_form. I tried configure it according to https://github.com/zokioki/flatpickr-rails but with no efect. It seems that simple_form ...
1
vote
0
answers
86
views
Rails: When adding a new enum column to my Postgres DB, why do I have to use change_table (not add_column) in my migration? And is it equally safe?
All the examples of adding a new enum column, which Rails 7 supports, require a change_table to add the column, like:
def up
create_enum :status, ["draft", "published", "...