Category "ruby-on-rails-5"

How to use Simple Form and Direct Upload ActiveStorage

I'm having a trouble when I try to use Simple Form gem for upload video. I'm using ActiveStorage and local storage for this. My form looks like this: = simple_

How do I make ActiveRecord search multiple tables (of similar schema) by default?

I have a very large table Metrics with a primary integer key named id. The primary key is 32 bit integer and is about to overflow. My attempted solution to this

Rails—get a random record from db?

To get a single random record from the db, I'm currently doing: User.all.sample But when there are 100000+ users, it takes a few seconds to load them all, jus

Change parameter name FORM_WITH VS FORM_FOR

I am using rails 5 and the form_with helper. My code works when using Form_for, but not Form_with. Is the :as parameter not valid with Form_with? View <%= f

Rationale of Rails 5 Join Table Generated Defaults

The Rails 5 command rails g migration create_foo_bar_join_table generates the following migration: class CreateFooBarJoinTable < ActiveRecord::Migration[5.0]

Rollback entire transaction within nested transaction

I want a nested transaction to fail the parent transaction. Lets say I have the following model class Task < ApplicationRecord def change_status(status,

How do you send JSON data in a rails-ujs Rails.ajax POST call (not using jQuery)?

I have a React client app that needs to talk to a Rails API. I want to use the rails-ujs method Rails.ajax. For example: Rails.ajax({ type: "POST", url: "

rails generated CSV file can't be downloaded

I'm trying to export my database to CSV file and download it but it doesn't download. I have a form with 2 different actions, Export to CSV and Export to JSON I

Rails 5 reads environment variables as string in YAML file

I have a Rails 5 app and I am trying to import my Environment Variables in a yaml file, which I can then import in the environment.rb. My config/aws.yml looks a

Change the default value for table column with migration

I try to change the default column value from false to true. But when I run rake db:migrate VERSION=904984092840298 I got the following ERROR. StandardError: A

Why won't Rails.cache store API responses?

I am trying to cache the results of API calls. My application makes multiple calls with the same result and I would like it to use the cache to save time. When

Rails: During asset precompile throws error key must be 16 bytes

I am storing my secret key in environment and /config/environments/production.rb has config.require_master_key = true uncommented config.require_master_key = t

How do I drop a foreign key if it exists in Ruby on Rails?

There's a function called index_exists? in ActionRecord, but no foreign_key_exists? on Rails 4.2.7. So when I call remove_foreign_key :parties, :franchise_gr

Pluralizations and Singularizations (Inflections) for "Media/Medium" in Rails 5

I'm working with Rails 5 an I just have created a Media model using scaffold tool. rails g scaffold media name:string And I got different names and routes and