- us-east-2
- us-east-1
- us-west-1
- us-west-2
- ap-east-1
- ap-south-1
- ap-northeast-3
- ap-northeast-2
- ap-southeast-1
- ap-southeast-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dot_to_hash(value) | |
return value unless value.is_a?(Hash) | |
value.deep_stringify_keys.each_with_object({}) do |(k,v), result| | |
root, child = k.split('.') | |
if child | |
result[root] ||= {} | |
result[root][child] = dot_to_hash(v) | |
else | |
result[root] = dot_to_hash(v) | |
end |
By default Rails wraps form errors in a div with the class field_with_errors
.
There are 2 ways to disable this.
First way is in the application.rb
environment file (doesn't make sense just to disable it on a specific environment?):
# config/application.rb
module ApplicationName
This is a super easy way to ensure that timestamps/datetimes etc render correctly according to the timezone that the object is in.
In our usage we have a time_zone
attribute on our models that stores the time zone in a format that we can find with active support.
Example American Samoa
, for more examples run bundle exec rake time:zones:all
in your rails project.
We weren't aiming to display the datetime in a format relative to the user, but rather just display that the time was in X time zone
# lets assume we have an attribute called start_time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/application_record.rb | |
class ApplicationRecord < ActiveRecord::Base | |
# Didn't change #update_column because it uses #update_columns under the hood. | |
def update_columns(attrs) | |
new_attrs = attrs.symbolize_keys | |
new_attrs[:updated_at] ||= Time.current if self.class.column_names.include?('updated_at') | |
super(new_attrs) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/helpers/application_helper.rb | |
module ApplicationHelper | |
# active_storage_item could be a blob or variant object | |
def proxy_url(active_storage_item, options = {}) | |
options.merge!(host: ENV['ASSETS_HOST']) if ENV['ASSETS_HOST'].present? | |
# proxy: 'true' allows you to stil have the original functionality while | |
# being able to proxy through a CDN. You've got to ensure that your CDN | |
# forwards this param otherwise active storage will always do the default | |
# behavior which is a redirect to the service. |
NewerOlder