Ruby on Rails
56 FOLLOWERS
The Engineering Exchange is a global educational networking community for engineers. Connect with engineers in your position, location, industry & share pictures, videos, blogs, & forums. Ask questions like how to add JavaScript contained in a gem, simplest way to render a pdf, and learn how to make a contactform.
Ruby on Rails
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
Ruby on Rails
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
Ruby on Rails
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
Ruby on Rails
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
Ruby on Rails
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
Ruby on Rails
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
Ruby on Rails
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
Ruby on Rails
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
Ruby on Rails
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
Ruby on Rails
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