- You MUST NOT try and generate a Rails app from scratch on your own by generating each file. For a NEW app you MUST use
rails new
first to generate all of the boilerplate files necessary. - Create an app in the current directory with
rails new .
- Use Tailwind CSS for styling. Use
--css tailwind
as an option on therails new
call to do this automatically. - Use Ruby 3.2+ and Rails 8.0+ practices.
- Use the default Minitest approach for testing, do not use RSpec.
- Default to using SQLite in development.
rails new
will do this automatically but take care if you write any custom SQL that it is SQLite compatible. - An app can be built with a devcontainer such as
rails new myapp --devcontainer
but only do this if requested directly. - Rails apps have a lot of directories to consider, such as app, config, db, etc.
- Adhere to MVC conventions: singular model names (e.g., Product) map to plural tables (products); controllers are plural.
- Guard against incapable browsers accessing controllers with `allo
This file contains 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
module Searchkick | |
class AsyncReindexStatus | |
include Redis::Objects | |
def id | |
'searchkick-async-reindex-status' | |
end | |
list :currently_reindexing | |
end |
This file contains 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
import React, { useMemo } from 'react'; | |
import { | |
Document as PDFDocument, | |
StyleSheet, | |
Page, | |
Font, | |
} from '@react-pdf/renderer'; | |
import dig from 'lodash.get'; | |
import PageFooter from './PageFooter'; | |
import CoverPage from './CoverPage'; |
This file contains 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
require 'oauth2' | |
client_id = 'your_client_id' | |
client_secret = 'your_client_secret' | |
redirect_uri = 'https://yoursite.com/oauth/authorize' | |
site = 'https://app.companycam.com' | |
client = OAuth2::Client.new(client_id, client_secret, site: site) | |
auth_url = client.auth_code.authorize_url(redirect_uri: redirect_uri, scope: 'read write destroy') |
This file contains 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
$provider = new \League\OAuth2\Client\Provider\GenericProvider([ | |
'clientId' => '', // Your client ID | |
'clientSecret' => '', // Your secret key | |
'redirectUri' => 'https://lonestarhazmatapp.com/wp-json/moserver/authorize', // This is where we redirect you/the user after they say it is okay for you to access CompanyCam on their behalf | |
'urlAuthorize' => 'https://app.companycam.com/oauth/authorize', | |
'urlAccessToken' => 'https://app.companycam.com/oauth/token' | |
]); | |
// If we don't have an authorization code then get one | |
// This would be in the Wordpress Admin UI, hook it up to a button or something |
This file contains 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
class BaseController < ApplicationController | |
before_action :doorkeeper_authorize!, except: [:index, :show, :create, :update, :destroy] # Anything not caught below | |
before_action :authorize_read_actions!, only: [:index, :show] | |
before_action :authorize_write_actions!, only: [:create, :update] | |
before_action :authorize_destroy_actions!, only: [:destroy] | |
def current_user | |
unless defined?(@current_user) | |
if doorkeeper_token.present? && !doorkeeper_token.revoked? | |
@current_user ||= User.find_by(id: doorkeeper_token.resource_owner_id) |
This file contains 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
client = OAuth2::Client.new(ENV['COMPANYCAM_UID'], ENV['COMPANYCAM_SECRET'], site: 'https://app.companycam.com') | |
# Get a auth URL to redirect user to | |
client.auth_code.authorize_url(redirect_uri: 'https://yoursite.com/oauth/companycam/callback') | |
# The user will accept of deny and then be redirected to the URL above | |
# the URL will have a parameter `code` if the user accepted. | |
# You will take the code and POST back to exchange for an access_token and refresh_token | |
client.auth_code.get_token(params[:code], redirect_uri: 'https://yoursite.com/oauth/companycam/callback') |
This file contains 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
[Unit] | |
Description=Puma HTTP Server for <%= "#{fetch(:application)} (#{fetch(:stage)})" %> | |
After=network.target | |
Requires=puma.socket | |
[Service] | |
Type=simple | |
User=<%= fetch(:deploy_user) %> | |
Environment=RAILS_ENV=<%= fetch(:rails_env) %> |
Attribute | Type | Description |
---|---|---|
version |
int |
The version of the photo collection, will increase as modifications are made |
collectionUUID |
string |
A unique identifier for the collection, it will remain the same with subsequent versions |
title |
string |
The title of the collection |
subtitle |
string |
The subtitle of the collection |
description |
string |
The long description explaining the project |
categories |
Array |
A list of categories the user applied to the collection |
This file contains 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
// project will be https://docs.companycam.com/#the-project-object | |
const project = await fetch ('https://api.companycam.com/v2/projects', { | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json', | |
'Authorization': 'Bearer {access_token}, | |
'X-CompanyCam-User': '{user_email}', | |
'X-CompanyCam-Secret': '{application_secret}' | |
}, |
NewerOlder