class User < ActiveRecord::Base
store :settings, accessors: [ :enable_notifications ]
attribute :enable_notifications, :boolean
end
# config/routes.rb
resources :plans, param: :uuid
edit_plan GET /plans/:uuid/edit(.:format) plans#edit
plan GET /plans/:uuid(.:format) plans#show
Class PlansController < ApplicationController
require 'net/http'
require 'uri'
class ApiJob < ApplicationJob
class Error < StandardError
end
queue_as :default
pg_dump local_development_database_name -c -C -f local_development_database_backup.sql
# This worked, with errors.
psql $external_connection_string < local_development_database_backup.sql
# This might be better.
pg_restore $external_connection_string -c -f local_development_database_backup.sql
# The `title` methods in each model are so similar it feels like they should be able to be shared.
# Normally this would be a good excuse to use a Concern, but is that even possible?
class Message < ApplicationRecord
def title
subject
end
end
# config/routes.rb
Rails.application.routes.draw do
# If you want to reference devise controllers in routes.rb
# make sure to wrap your route inside the devise_scope block
devise_scope :user do
root "devise/sessions#new"
end
class NotificationsMailer < ApplicationMailer
def notify
@user = params[:user]
mail(to: @user.email, subject: "You have a new notification") do |format|
if @user.admin?
# This method will use app/views/layouts/mailer.html+custom_admin_layout.erb
format.html { render layout: 'mailer', variants: :custom_admin_layout }
else
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
# Will prompt the user for a username and password if on the staging environment.
# This helps keep the app locked down and prevents bots from crawling the site.
before_action :http_basic_authentication, if: :http_basic_authentication_enabled?
private
class User < ApplicationRecord
... # Lot's of methods making it hard to scan this class at a glance.
# Orignal method created earlier in this project's life
def formatted_name
self.first_name + " " + self.last_name
end
class NotificationsMailer < ApplicationMailer
# https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-callbacks
after_action :prevent_delivery
def unread
@user = params[:user]
mail(to: @user.email, subject: 'Here's what you missed...')
end