Skip to main content

New answers tagged

0 votes

How to test Controller with sign in user on Rails 8 authentication

setup do @user = users(:one) sign_in_as(@user) end Working for me in new 8.1 rails project
Headless's user avatar
  • 253
0 votes

How to embed an iframe with ActionText/Trix on Ruby on Rails?

An alternative is to re-render the Trix content after saving. I built a simple package to solve this problem that can properly render YouTube videos, Tweets, code blocks, and images from Trix, here's ...
Justin Hammond's user avatar
Best practices
0 votes
0 replies
0 views

How should I structure NestJS services when one endpoint needs to update multiple entities (e.g., InvestorProfile and TaxProfile)?

checkout the CQRS pacakage from NestJS, inside check Sagas/Event handlers. If you want to decouple your system Event Driven Architechture is the way
Joy Biswas's user avatar
  • 6,553
0 votes

i18n Pluralization

Using Ruby on Rails You have #{n} #{'kid'.pluralize(n)} See pluralize doc for options & alternatives: https://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-pluralize
Constantin De La Roche's user avatar
0 votes

Assertions for travel_to with attribute-based timezone

Referring to the documentation, the problem can be ascertained through toggling of configuration and adjusting the test. puts Time.current travel_to Time.zone.local(2025, 8, 8, 9, 59, 58) puts ...
Jerome's user avatar
  • 6,355
0 votes

How to handle ActiveRecord::RecordNotUnique error

This is a bit old but here's the difference in my testing with Rails 8: If you create an ActiveRecord validation on your model (for example: validates_uniqueness_of :field_name) then you'll get ...
jonmakesapps's user avatar
0 votes

How to package ruby on rails app into an executable

Tebako seems like the most promising option currently working on finding the way to package a rails app into an offline app. This article seems to show that it is very much possible using tebako and ...
yungindigo's user avatar
0 votes

Can't connect to MongoDB Atlas (free tier)

Adding &authSource=admin to the connection URI did the trick. Thx to a friend!
Thomas's user avatar
  • 78
-1 votes

Can't connect to MongoDB Atlas (free tier)

If you can use the same URI from a different client, the problem would appear to lie in the Ruby on Rails client side. It appears the SCRAM-SHA-1 authentication mechanism failed. Is it possible this ...
Spencer Brown's user avatar
0 votes

How can I get the utc offset in Rails?

If you want the offset as a number you need to divide by a float ( 3600.0 or 1.hour.to_f ) otherwise offset that are not on the hour will be incorrect (e.g. Asia/Rangoon has an offset of UTC+06:30)
Alex Slotty's user avatar
0 votes

ActiveAdmin complaining about ransackable_atttributes

I believe you're probably migrating from MetaSearch gem (Ransack predecessor). _starts_with is not a predicate available in Ransack. On Ransack, it's just start (see it on the official docs). ...
lmtaq's user avatar
  • 560
0 votes

How to disable Rails test parallelization *just* for system tests?

Following this suggestion from the ruby forums I was able to do this by simply prepending this line in my test/application_system_test_case.rb before requiring test_helper.rb: ENV["...
vlz's user avatar
  • 1,058
0 votes

How can I send mail with rails without a template?

I was really struggling with this in rails 8. I wanted to send a multipart email that ALSO had attachments. I tried every other answer here. This was my final working code def send_adhoc_email(message)...
Nathan Kidd's user avatar
Best practices
0 votes
0 replies
0 views

How should I structure NestJS services when one endpoint needs to update multiple entities (e.g., InvestorProfile and TaxProfile)?

transactions are best solution for hear https://docs.nestjs.com/techniques/database#typeorm-transactions
beqa gerliani's user avatar
0 votes

How to sign in a user and create associated records with factories when testing

There seems to be some confusion there around factories usage. You use the factories just to mock a representation of the object and then you manipulate it according to your needs (such as using it ...
lmtaq's user avatar
  • 560
0 votes

error installing rails - alternate installation path possible

Often, a user might bump into permissions errors when trying to install gems on the same Ruby version that came installed on your OS. That version is usually "protected", it's meant to be ...
lmtaq's user avatar
  • 560
0 votes

Can you create a database backed rails model without a table?

Diogo is correct, views do work in Rails, for a long time already. But views seem overkill to me in this case. The proper thing to use in SQL would be a TYPE. A TYPE is an empty carrier for a table ...
PMc's user avatar
  • 118
0 votes

An error occurred while installing mysql2 (0.5.4), and Bundler cannot continue - in rails project

For me, the error was "An error occurred while installing mysql2 (0.5.4), and Bundler cannot continue" I just had to run this command with explicit version that is the same as in my Gemfile: ...
Bekzod Jon's user avatar
Best practices
1 vote
0 replies
0 views

How should I structure NestJS services when one endpoint needs to update multiple entities (e.g., InvestorProfile and TaxProfile)?

i believe you should use transaction in your exemple since you don't want to update one and the other throw an error and to answer your question i think it's better if you put taxProfileService.update ...
Rayan Allali's user avatar
0 votes

error installing rails - alternate installation path possible

Your OS user apparently has no write privilege on /var/lib/gems/3.2.0/gems/websocket-driver-0.8.0/CHANGELOG.md In order to fix it, you need to grant your OS user the necessary privileges over /var/...
Lajos Arpad's user avatar
  • 80.4k
0 votes

Rails 7 - javascript importmap tags - custom for logged and nologged users

add in importmap.rb pin "jquery", to: 'admin/jquery.js', preload: ['admin'] pin "dashboard", to: 'admin/dashboard.js', preload: ['admin'] pin "select2", to: "js/...
saqib's user avatar
  • 106
0 votes

Problem with migrated rails 8 sprockets/importmap sprockets errors on app/javascript files

I fixed it by just upgrading to use propshaft instead of sprockets, which was next on my list anyway.
Robert Reynolds's user avatar
0 votes

Test Data Generator CSV - Similar to Mockaroo

I still use Mockaroo sometimes, though Fakerbox has become my first choice because it’s straightforward and covers most formats I need during testing.
sri's user avatar
  • 1
0 votes

Rails 8 importmap and chart.js

importmap-rails v2 is forever broken. Chart.js has a relative import which only works relative to cdn and it is not downloaded by bin/importmap: import {...} from "../_/MwoWUuIu.js" Using a ...
Alex's user avatar
  • 31.3k
0 votes

Turbo Rails (8x) with `link_to` raises "Can't verify CSRF token authenticity"

link_to does not support the params option. You will notice that in your logs there are no parameters passed when using link_to which is why this is failing. The reason this works for button_to is ...
engineersmnky's user avatar
0 votes
Accepted

Can't get rails to match a nested controller to its layout

From the docs: For instance, if you have PostsController and a template named app/views/layouts/posts.html.erb, that template will be used for all actions in PostsController and controllers ...
mechnicov's user avatar
  • 16.2k
0 votes

Querying for date range in rails

Couple modern answers. You can do: Post.where created_at: 1.day.ago..Time.now # in the last day Post.where created_at: ..2.day.ago # more than 2 days ago Post.where created_at: 2.day.ago.. # in ...
Adverbly's user avatar
  • 2,199
0 votes

My rake task is not showing up in rake -T

I had a similar situation to Yathi's, where the issue was that I wasn't using a standard Rakefile. As they mention, the default Rakefile will load tasks from lib/tasks, thanks to the lie Rails....
Sam's user avatar
  • 6,710
0 votes
Accepted

Rails logs show `DEBUGGER: Debugger can attach via UNIX domain socket` but VS Code rdbg says "Can not find attachable Ruby process."

It turned out to be caused by having an old version of the ruby/debug gem. In the working app, ruby/debug was 1.9.2 (I looked in Gemfile.lock) and in the non-working site, it was 1.8.0. When I ...
Sam's user avatar
  • 6,710
0 votes

Rails—get a random record from db?

Consider Disabling ActiveRecord Caching It can sometimes be important to disable Rails caching, such as if you plan to run the same query multiple times within the same HTTP request: random_user = ...
Matt's user avatar
  • 6,410
Best practices
0 votes
0 replies
0 views

copying and deleting a collection of records from one postgresql table to a second table

On top of the pure SQL answer, I'd like to address your questions: • whether this approach is sound, and; Whenever I have doubts like this, there's only one answer that works for me: tests. Set up ...
Greg's user avatar
  • 6,791
Best practices
4 votes
0 replies
0 views

copying and deleting a collection of records from one postgresql table to a second table

This would be very simple and safe using native SQL with a data modifying CTE. Here is an illustration: with t as ( delete from itemised_origin_rows where <your condition(s) here> ...
Stefanov.sm's user avatar
  • 13.2k
0 votes

Devise - remember me not working? LocalHost Issue?

By default, in the development environment, a new secret_key_base is generated each time the application restarts. This causes previously signed cookies to become invalid and unusable. Since Devise ...
Constantin De La Roche's user avatar
0 votes

"rails test" command prints out a very long output

This is fixed by https://github.com/rails/rails/pull/45882 The implementation of inspect simply loops over all instance variables, but interestingly it doesn't call the instance_variables method to ...
Fangxing's user avatar
  • 6,225
0 votes

Where is Ruby's ERB format "officially" defined?

This is a great question. There are several ways to answer it, and I'll try and pull them all together into this one answer. The first answer is to say, like the original answer here, that "ERB&...
Sam's user avatar
  • 6,710
0 votes

Create a select tag with some options grouped and others not grouped

There's a simpler way to achieve this, by combining options_for_select and grouped_options_for_select together: options_for_select(["Income"]) + grouped_options_for_select([["Auto",...
Rolandas Barysas's user avatar
0 votes

Rails App crashes when https request is made after upgrading to macos Tahoe 2025

I can see your puma version 6.4.3 which had some issue with openssl version determine logic, if you upgrade to 6.5 might solve your problem, because they fixed some openssl version determining issue. ...
Zogoo's user avatar
  • 53
3 votes
Accepted

Rails8/Devise custom action found in routes, but 404 when called

You have to give the exact mapping name to devise_scope, regardless of any namespace nesting: namespace :api do namespace :v1 do devise_for :users devise_scope :api_v1_user do # ... ...
Alex's user avatar
  • 31.3k
1 vote
Accepted

How to make jsbundling-rails and yarn work together?

Well, data from your question Yarn is the part of NVM-based Node: which yarn /home/[user]/.nvm/versions/node/v25.0.0/bin/yarn When you try to call this command through SSH ssh user@server_ip which ...
mechnicov's user avatar
  • 16.2k
0 votes

How to check for a JSON response using RSpec?

Hell-o! You can use the json_expressions gem to use json in the simplest way: let(:expected_result) { { a: 0, b: 2 } } ... it 'expect response to match expected' do expect(subject).to ...
Sergio Belevskij's user avatar
1 vote

How can I use Rails internal error reporting to swallow the error in production but not in test or development

My workaround has been to create a custom `ErrorSubscriber` : # config/initializers/error_subscriber.rb class ErrorSubscriber def report(error, handled:, severity:, context:, source: nil) args = ...
fguillen's user avatar
  • 39.5k
1 vote

Rails 7 / GraphQL-Ruby: ActionCable subscription always 403 Forbidden when connecting with JWT

Answer In my case the WebSocket 403 Forbidden was not caused by ActionCable itself — the connection was being rejected by Rack::Attack. Rails logged only: Started GET "/cable?token=[FILTERED]&...
Radosław Matteo Sakowicz's user avatar

Top 50 recent answers are included