---
title: "ruby on rails | Today I Learned | OOZOU"
description: "Short, practical ruby on rails notes from the OOZOU team."
canonical: https://oozou.com/til-topics/ruby-on-rails
locale: en
---

# ruby on rails | Today I Learned

> Short, practical ruby on rails notes from the OOZOU team.

- [Use Pundit Policies to manage permitted parameters, defaults and per action](https://oozou.com/til/use-pundit-policies-to-manage-permitted-parameters-defaults-and-per-action-188) ([markdown](https://oozou.com/til/use-pundit-policies-to-manage-permitted-parameters-defaults-and-per-action-188.md)) (2022-02-10): To manage permitted params you can add permitted\attributes and permitted\attributes\for\#{action} in your policies e.g.
- [Use `requestSubmit` for form submits with Turbo](https://oozou.com/til/use-requestsubmit-for-form-submits-with-turbo-155) ([markdown](https://oozou.com/til/use-requestsubmit-for-form-submits-with-turbo-155.md)) (2022-01-31): Turbo listens to submit events on form.    Hence, always use requestSubmit to submit  a form using JS.
- [Ignore bundled gems for Rubocop and ESLint in GitHub Actions](https://oozou.com/til/ignore-bundled-gems-for-rubocop-and-eslint-in-github-actions-154) ([markdown](https://oozou.com/til/ignore-bundled-gems-for-rubocop-and-eslint-in-github-actions-154.md)) (2022-01-19): Rails projects will often install gems into the vendor directory in GitHub actions so we can cache them for the consecutive runs.
- [Rails 6, Ruby 3, Bootstrap 5 and Hotwire](https://oozou.com/til/rails-6-ruby-3-bootstrap-5-and-hotwire-115) ([markdown](https://oozou.com/til/rails-6-ruby-3-bootstrap-5-and-hotwire-115.md)) (2021-04-18): Extending the blogpost from Bootrails with Hotwire:   All the fancy new things (as of when I'm writing this TIL):
- [Rails Cache-Control](https://oozou.com/til/rails-cache-control-77) ([markdown](https://oozou.com/til/rails-cache-control-77.md)) (2020-10-27): For enabling setting cache-control headers of static assets and using a CDN on Heroku:
- [Fix input on Heroku's rails console](https://oozou.com/til/fix-input-on-heroku-s-rails-console-73) ([markdown](https://oozou.com/til/fix-input-on-heroku-s-rails-console-73.md)) (2020-10-14): If you end up pasting lots of lines into a rails console on Heroku (or else where), you might get issues with the lines "bleeding" into each other.
- [Unique ID for DOM in Rails](https://oozou.com/til/unique-id-for-dom-in-rails-75) ([markdown](https://oozou.com/til/unique-id-for-dom-in-rails-75.md)) (2020-10-14): Rails has many great view helpers, one of which is dom\id:*
- [Add new types to Rails 5 attributes API](https://oozou.com/til/add-new-types-to-rails-5-attributes-api-13) ([markdown](https://oozou.com/til/add-new-types-to-rails-5-attributes-api-13.md)) (2020-10-13): The Rails 5 attributes API allows us to build form objects very easily.
- [Attaching file to ActiveStorage without HTTP](https://oozou.com/til/attaching-file-to-activestorage-without-http-19) ([markdown](https://oozou.com/til/attaching-file-to-activestorage-without-http-19.md)) (2020-10-13): If you want to attach a file you generated on disk or downloaded from a user-submitted URL, you can do it like this.
- [Create a Hash from an Enumerable (Rails 6.0)](https://oozou.com/til/create-a-hash-from-an-enumerable-rails-6-0-6) ([markdown](https://oozou.com/til/create-a-hash-from-an-enumerable-rails-6-0-6.md)) (2020-10-13): New method allowing you to create a Hash from an Enumerable:
- [Create idempotent migrations](https://oozou.com/til/create-idempotent-migrations-28) ([markdown](https://oozou.com/til/create-idempotent-migrations-28.md)) (2020-10-13): When you want to write destructive migrations please use if\exists: true when you’re trying to remove a table and check for a table existence when you want to add or remove a column…
- [How to find god objects in your project (Rails)](https://oozou.com/til/how-to-find-god-objects-in-your-project-rails-40) ([markdown](https://oozou.com/til/how-to-find-god-objects-in-your-project-rails-40.md)) (2020-10-13): Go to your project root and cd into app/models (using CLI obviously) then run wc -lw \ | sort -u*
- [HTML forms that submit to another action](https://oozou.com/til/html-forms-that-submit-to-another-action-10) ([markdown](https://oozou.com/til/html-forms-that-submit-to-another-action-10.md)) (2020-10-13): I've known for a long time that you can submit values with submit buttons so you can track which button was used to submit the form e.g.
- [If you want to override previously set order](https://oozou.com/til/if-you-want-to-override-previously-set-order-25) ([markdown](https://oozou.com/til/if-you-want-to-override-previously-set-order-25.md)) (2020-10-13): If you want to override previously set order (even through default\_scope), use reorder() instead.
- [Limited has_many associations](https://oozou.com/til/limited-has_many-associations-31) ([markdown](https://oozou.com/til/limited-has_many-associations-31.md)) (2020-10-13): Limited has_many associations
- [List your model names](https://oozou.com/til/list-your-model-names-58) ([markdown](https://oozou.com/til/list-your-model-names-58.md)) (2020-10-13): NOTE: RUBYOPT=-W0 avoids verbosity when running rails command which suppresses warnnings.
- [Postgres Functions & Non-sargable Queries](https://oozou.com/til/postgres-functions-non-sargable-queries-48) ([markdown](https://oozou.com/til/postgres-functions-non-sargable-queries-48.md)) (2020-10-13): Using postgres functions inside a where clause can make a query non-sargable.
- [PostgreSQL UPDATE Join ](https://oozou.com/til/postgresql-update-join-64) ([markdown](https://oozou.com/til/postgresql-update-join-64.md)) (2020-10-13): This query shows how to use the PostgreSQL UPDATE join syntax to update data in a table based on values in another table. for example;
- [Scope or scope in Rails](https://oozou.com/til/scope-or-scope-in-rails-11) ([markdown](https://oozou.com/til/scope-or-scope-in-rails-11.md)) (2020-10-13): scope :human, -> { user.or(author) } scope :terminator, -> { admin.or(robot) } `
- [Show TODO and other notes in your Rails app](https://oozou.com/til/show-todo-and-other-notes-in-your-rails-app-7) ([markdown](https://oozou.com/til/show-todo-and-other-notes-in-your-rails-app-7.md)) (2020-10-13): Did you know you can show all TODOs/OPTIMIZE/FIXME in your rails app with rails notes?
- [Tag rails logs with useful information](https://oozou.com/til/tag-rails-logs-with-useful-information-32) ([markdown](https://oozou.com/til/tag-rails-logs-with-useful-information-32.md)) (2020-10-13): Just learned about tagged logging in rails. Did you know you can tag a log by using
- [Use minItems/maxItems in collection JSON schemas](https://oozou.com/til/use-minitems-maxitems-in-collection-json-schemas-1) ([markdown](https://oozou.com/til/use-minitems-maxitems-in-collection-json-schemas-1.md)) (2020-10-13): To make your collection JSON schemas more reilable use minItems and maxItems so that you can trust your API.

All notes: [Today I Learned](https://oozou.com/til) ([markdown](https://oozou.com/til.md)).

---

Contact OOZOU: hello@oozou.com · +66 2544 0000 · https://oozou.com/contact

More for AI agents: https://oozou.com/llms.txt · every page has a markdown twin at its URL plus ".md"
