Is it more appropriate to generate a controller with subfolders and then define the routes manually, or to use the 'rails generate controller' command which creates routes automatically but does not organize the controller into subfolders?
Ruby on Rails
by DannHernn
19h ago
In the development of a REST API with Rails, there is a question about the best way to structure controllers and routes. Two options are proposed: Generating the controller with subfolders and defining the routes manually: rails generate controller api/v1/customer/create Then, manually define the routes in the config/routes.rb file: Rails.application.routes.draw do namespace :api do namespace :v1 do namespace :customer do post 'create', to: 'create#create' end end end end Using the ‘rails generate controller’ command which creates routes automatically but d ..read more
Visit website
ActiveStorage::Attached::One#signed_id returning nil
Ruby on Rails
by m.b.
19h ago
Hello! I tried creating a custom multi file uploader based on ActiveStorage JS bundle. I have an Object model with has_many :attachments association. Attachment model has_one_attached :file Simply put, i’m uploading my files using a following code: const upload = new DirectUpload(file, url) upload.create((error, blob) => { if (error) { // Handle the error } else { // Add fields_for entry to a form and fill the `file` // input with returned `blob.signed_id` } }) And on successfull upload, my file input value is being filled with uploaded blob.signed_id. And here is the ..read more
Visit website
Generating a unique token for invitation system. Anything I'm missing?
Ruby on Rails
by sly
1d ago
before_validation :generate_token, on: :create, if: :token_blank? private def generate_token self.token = SecureRandom.hex(32) end There’s a unique index on the database field itself (using migration) - but on the model this is all I have. Anything I should add to make this more robust? 1 post - 1 participant Read full topic ..read more
Visit website
Open Source Tool to Deploy Rails on EC2
Ruby on Rails
by Bala Paranj
3d ago
Please check out HiveGrid project. It is designed to simplify deploying Rails 7 apps to EC2. 1 post - 1 participant Read full topic ..read more
Visit website
Limiting the number of open database connections in migrations
Ruby on Rails
by matthew healy
3d ago
I work on a Rails app with a multi-tenancy setup. When a new customer is added we dynamically create a new database for them. In our migrations we override ActiveRecord::DatabaseConfigurations#configs_for to load the configurations for all customer databases, so that we can run bundle exec rails db:migrate and it “just works”. However, the environment where we run migrations (GCP Cloud Run jobs + Cloud SQL) has an artificial limit of 100 database connections at a time, which we cannot currently work around. I’m wondering, is there a way I can reliably limit the total number of database connect ..read more
Visit website
Puma plugin in my Rails app
Ruby on Rails
by Javier Valencia
3d ago
Hi there! I’m trying to write my first Puma plugin, copying tmp_restart.rb as example and place the code inside libdirectory of my Rails app. lib/puma/plugin/pruebas.rb: # frozen_string_literal: true require 'puma/plugin' Puma::Plugin.create do def start(launcher) puts 'Hola mundo!' p ['launcher', launcher] in_background do loop do sleep 2 puts 'Hello world!' end end end end And I add these lines to puma.rb: # Plugin Pruebas plugin :pruebas But when I run bin/rails server I got this error: => Booting Puma => Rails 7.1.3.2 applicat ..read more
Visit website
STI with the devise User model
Ruby on Rails
by Adevfz
4d ago
Hello everyone, I’m trying to have multiple models which inherits from the devise User model. I’ve made the following migration files: # frozen_string_literal: true class DeviseCreateUsers < ActiveRecord::Migration[7.1] def change create_table :users do |t| ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" t.string :username, null: false, default: "" t.string :name t.string :surname t.string :address t.string :phone t.string :mobile t.string :city ..read more
Visit website
Newly created app just renders 500.html not showing any errors
Ruby on Rails
by Kjell
4d ago
Hi *, I have a really strange problem with a newly created rails 7 app. I added just one single route so far, but every request leads to /public/500.html not showing any error in the logs/console. I already tried dropping out web_console, and explicitly set config.log_level = :debug and config.action_dispatch.show_exceptions = :all within application.rb. Files from /public are being served correctly so far, but noting else. That’s everything the log says: web-1 | => Booting Puma web-1 | => Rails 7.1.3.2 application starting in development web-1 | => Run `bin/rails server --help ..read more
Visit website
Notifying a view if a given values exists in a table
Ruby on Rails
by philipgs
6d ago
Hi - I want to enter a unique_id (string) into an input box in a view and then for it to return an output showing if this id exists in a given table in the dbase. How would I code this in controller and view. Regards 1 post - 1 participant Read full topic ..read more
Visit website
API Design Library
Ruby on Rails
by caiotarifa
6d ago
I have been using Laravel Orion to build APIs in PHP projects and have found it extremely useful. Now I’m diving into a Rails project and wondering if there is something similar to Laravel Orion for Rails. I am looking for a single gem that comes with well-established concepts for configuring APIs, covering essential functionalities like filtering, sorting, pagination, searching and batch actions. Does anyone have any recommendations or suggestions? 1 post - 1 participant Read full topic ..read more
Visit website

Follow Ruby on Rails on FeedSpot

Continue with Google
Continue with Apple
OR