XIO

xWire

Posts from every feed QUEST has found across the web — blogs, news, podcasts, channels and more.

Ruby on Rails Discussions - Latest posts

Latest posts

Cancel running query in console on ctrl+c

Right now, if in a console with PG, I was to do: `ApplicationRecord.connection.execute(“SELECT pg_sleep(100)”) Then press ctrl+c to cancel the ruby code, the query is still running and holding the connection. This means: It is still using server capacity (imagine it’s heavier than a sleep). If I run ApplicationRecord.connection.execute("SELECT 1"), that will actually wait until after the 100s are elapsed before even starting. At a high level, could we make perform_query rescue Interrupt and…

Looking for a v0 alternative for a Rails side project?

I’m building a small Rails side project and keep running into v0 as an option for quickly getting UI going. The thing is, my app is already a Rails app with ERB views and a bit of Hotwire, so I’m not sure how well a tool built around generating components would fit my existing setup. I’m also hesitant because I don’t want to spend time learning a workflow that doesn’t mesh with Rails conventions. I’ve seen people mention various AI app builder alternatives but I don’t have firsthand experience…

Write-only fields with ActiveRecord

This could be a solution which doesn’t interfere too deeply. class Account < ApplicationRecord include WriteonlyEncryption attr_encrypt_writeonly :pin end Provided functionality with a module like that. It adds the getter and setter #pin and #pin=. module WriteonlyEncryption extend ActiveSupport::Concern class_methods do def attr_encrypt_writeonly(*names, public_key: Rails.application.credentials.writeonly_encryption_public_key) raise ArgumentError, "attr_encrypt_writeonly needs at least one…

How do you check a migration before it runs in production?

Glad it helps, @RepoRover. I can’t point to one specific incident of my own, so I’d rather describe what a full-size copy typically shows than invent a story. The usual catches are a backfill or index build that takes minutes on real data but milliseconds on a small sample, and a null: false change that fails on old rows nobody expected to be null. Those only appear with realistic volume and messy legacy data. For freshness, a scheduled restore from the latest backup, weekly or nightly, works…

Putting a CDN in front of ActiveStorage

One thing I’d test explicitly is the authorization path on a cache hit, not only on a miss. With signed URLs, the CDN should validate the signature and expiry for each viewer request even when it already has the object cached; the storage origin should remain private. A simple test matrix—valid URL, expired URL, and an unsigned request, each once cold and once warm—will catch whether the edge policy is doing what you expect. Also watch proxy cache-miss latency and image-processing load on Rails…

How do you check a migration before it runs in production?

A few things that have helped in practice: run the migration against a restored, recent copy of production (with personal data scrubbed) rather than a small sample, because lock and timing problems only show up at real table sizes. Time it there, and if it takes more than a few seconds, split it. The strong_migrations gem catches most of the dangerous patterns at development time, such as adding an index without `algorithm: :concurrently` or changing a column type in place. For column changes,…

How do you check a migration before it runs in production?

I’m trying to understand how teams check a Rails migration before it reaches a production PostgreSQL database. What do you look at in review: the migration file, the diff of schema.rb or structure.sql, or the SQL it runs? What has bitten you in production: a rename_column or remove_column under running code, an add_index or change_column that locked a large table, a new null: false on rows that already existed? What happened, and what did it take to put right? Do you run migrations against a…

How can I add multiple currencies to a travel booking application built with Rails?

A setup that works well for this: 1. Store every price as an integer amount plus a currency code (for example `price_cents` and `price_currency`). The money-rails gem gives you `monetize :price_cents` and handles formatting and arithmetic, so you never store floats. 2. Keep one base currency for your inventory and convert only for display. Fetch exchange rates on a schedule (a daily job is enough for most booking sites) from a provider such as Open Exchange Rates or the ECB feed, and cache…

Putting a CDN in front of ActiveStorage

@lylo, I wouldn’t use the gsub workaround suggested above. Removing /rails/representations won’t turn a Rails URL into a Spaces object key. The built-in Spaces CDN serves bucket objects; proxy URLs need a CDN configured with your Rails app as its origin. To make the earlier partial suggestion concrete, I’d call a CDN URL helper from app/views/active_storage/blobs/_blob.html.erb. The generated URL should have the CDN hostname and keep the Rails proxy path. As @Janusz_M explained, cache misses…

How can I safely handle file uploads with Active Storage?

To add some practical basics for a beginner: Active Storage does not validate uploads for you, so add your own checks in the model. Limit the allowed content types (for example only image/png and image/jpeg) and the maximum file size, and do not trust the filename or extension the browser sends. Keep your storage bucket private and serve files through Rails URLs, which are signed and expire. For anything that is not an image, prefer forcing a download instead of showing it inline in the…

Redirect after form submission with result page

Another option besides disabling Turbo: keep the redirect (post/redirect/get) and persist the result of the bulk edit so the next page can show it. For example, collect the before/after pairs while you save, e.g. `changes = tags.map { |t| [t.name_was, t.name] }`, then store them on a small BulkEdit record (or a JSON column) and `redirect_to bulk_edit_path(record)`. The show page reads the stored pairs, so a refresh or the back button works too, and you don’t end up with a page living at a POST…

Allow foreign_type on a non-polymorphic belongs_to

My goal is the opposite of a second column: store only item_type + item_id, but expose them as if the model had separate comment_id, task_id, … columns. Today it has a real comment_id and I want to move it to the polymorphic pair, so it can point at more types, without an API change. Serializers, includes and filters are built on associations, so each type has to stay an association: belongs_to :item, polymorphic: true belongs_to :comment, foreign_key: :item_id, foreign_type: :item_type,…

Allow foreign_type on a non-polymorphic belongs_to

The ID part of a polymorphic association is only meant to be used along with its corresponding *_type column. It’s not meant to additionally be used in a separate belongs_to. If you need this kind of thing then although it might feel like duplication, add an additional foreign key column (in this case comment_id) instead of trying to rely on using just one part of the polymorphic key, that is, the part found in the item_id column.

Allow foreign_type on a non-polymorphic belongs_to

When you want one type of a polymorphic reference as its own association, the obvious approach silently ignores the type column: class Activity < ActiveRecord::Base belongs_to :item, polymorphic: true belongs_to :comment, foreign_key: :item_id end comment reads item_id and ignores item_type, so it returns a comment even when the activity points at something else: task = Task.find(5) activity = Activity.create!(item: task) # item_type: "Task", item_id: 5 activity.comment # => Comment.find(5), an…

CDN caching for Active Storage private assets without exceeding memory

Right, I think those two expiration times are separate. The expires_in in private_url controls the S3 presigned URL, not CloudFront’s cache TTL. For your setup, I’d have Rails check permissions and generate a short-lived CloudFront signed URL. CloudFront could then serve the cached file or fetch it directly from your private S3 bucket using Origin Access Control. The cached object can stay around longer than the URL itself, since CloudFront checks the signature on each new request. I’d watch is…

Anyone here using Rails with a no-code AI app builder for internal tools?

I’m a Rails developer in Portland working on a small internal dashboard for my team. We already have a Rails app, but I keep seeing no-code and AI app builder tools pitched as faster ways to spin up the front end and simple CRUD screens. I’m weighing whether to try one alongside our existing Rails stack or just keep everything in Rails and avoid the extra dependency. My main concern is whether these tools play nicely with a real Rails backend and Postgres, or if they lock data into their own…

Community support: SF Ruby Conf scholarship program (free access to students and newcomers)

The October 30 deadline and the caveat that travel and accommodation aren’t covered are the details worth repeating, since free registration can still leave a real cost for people outside the Bay Area. The three-minute application also seems designed to reduce friction for students, recent grads, career changers, and underrepresented groups. Highlighting those eligibility groups in local Ruby and meetup spaces could help reach newcomers who might otherwise assume the scholarship isn’t for them.

How can I safely handle file uploads with Active Storage?

Mirroring across different providers is a solid safety net, but it really only covers storage-side failure. Since the thread opened with handling untrusted inputs, I’d keep that concern separate: mirroring won’t change what happens when a hostile file is parsed or previewed. Validating content types server-side and doing any processing in an isolated context still matters alongside redundant storage. Both layers together seem more robust than either alone.

Proposal: Action Cable should accept a WebSocket handshake with no Origin header, as Action Controller does

The comparison to valid_request_origin? is the part that convinces me. If Action Controller already treats a nil origin as acceptable because some user agents omit it, having Action Cable reject the same handshake seems inconsistent for no clear security gain. As you note, the CSWSH attack depends on a browser, and browsers send Origin on WebSocket handshakes per RFC 6455. A non-browser client that omits it isn’t the threat the check targets. I’d want to make sure the change is well documented…

What is a good database structure for products, orders, payments, and inventory in a Rails POS application?

Walter’s point about older order items missing keys is the practical worry with the JSON snapshot approach. If the structure only ever grows, reading back a partial hash and treating absent keys as nil or a default seems workable, but that logic has to live somewhere central rather than being repeated per screen. The real risk is when a key gets renamed or its meaning shifts, since nothing distinguishes old records from new ones. Storing a small version marker alongside the snapshot would let…

Looking for Ruby on Rails Programming Buddies

There’s a lot of Ruby on Rails that was not covered during my time at a coding bootcamp. There’s vulnerabilities that was not covered and the many modules that Ruby on Rails has pre-built such as web-socket/action cable that I have not had to time to practice with. I am not so versed in understanding version control of ruby ‘gems’ and how it affects the project as a whole ie breaking the codebase.

Looking for Ruby on Rails Programming Buddies

Your goal of moving from intermediate toward work-ready Rails skills is a sensible one. Since you mentioned having a few hundred hours already, I’d suggest focusing on the parts that tend to come up in hiring conversations: testing with RSpec or Minitest, background jobs, and reading other people’s codebases rather than only building your own. Pairing up works best when there’s a shared small project or a code review exchange, so it might help to mention what kind of work you’d like to…

Rails security releases: 8.0.5.2 and 8.1.4.1

Hello, Rails community! Rails Versions 8.0.5.2 and 8.1.4.1 have been released. These are security updates addressing 21 security issues falling into a few themes: Possible arbitrary file read, file write and remote code execution in Active Storage image and video processing Possible Strong Parameters bypass in Parameters#each_key Possible IP spoofing in remote_ip through the Forwarded header (8.1 only) Multiple possible XSS vulnerabilities in Action View helpers, and one in the Active Support…

Range conditions on multi-column `composed_of` aggregates

One thing that worries me about compare_with: is what happens to the other mapped columns. In your Measurement example, a range from 1 kg to 10 kg would generate a condition on quantity_value alone. Wouldn’t that also match a record containing 5 lb? That seems like a fairly subtle bug, because the query looks correct at the value-object level but loses an important part of its meaning when translated to SQL. For quantities stored with a unit, I’d expect the generated condition to include…