Add global property to Doodads

This commit is contained in:
Jesse C. Fisher 2023-11-22 12:11:12 +00:00
parent b4d0afe90d
commit 6bd0e4c1de
8 changed files with 24 additions and 4 deletions

View File

@ -31,6 +31,7 @@ p
h1
font-size: 7vmin
margin-bottom: 0
padding-left: .33em
font-family: "Press Start 2P", "Anton", Impact, fantasy, sans-serif
// h2
@ -76,9 +77,9 @@ header
border-radius: 0 13em 0 0
font-size: 2em
> h1
padding-top: .6em
align-self: start
text-indent: .4em
// padding-top: .6em
// text-indent: .4em
#home-headline, .home-headline

View File

@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
# skip_before_action :verify_authenticity_token
after_action :flash_to_http_header
before_action :get_footer_tokens
before_action :get_global_doodads
if (Rails.env.development? || Rails.env.test?)
include Pundit::Authorization
@ -43,6 +44,10 @@ class ApplicationController < ActionController::Base
@footer_tokens = policy_scope(Token)
end
def get_global_doodads
@global_doodads = policy_scope(Doodad).where(is_global: true)
end
def flash_to_http_header
return unless request.xhr?
return if flash.empty?

View File

@ -68,6 +68,6 @@ class DoodadsController < ApplicationController
# Only allow a list of trusted parameters through.
def doodad_params
params.require(:doodad).permit(:body, :user_id, :is_public)
params.require(:doodad).permit(:body, :user_id, :is_public, :is_global)
end
end

View File

@ -5,6 +5,7 @@
= f.input :body
= f.hidden_field :user_id
= f.input :is_public
= f.input :is_global
.form-actions
= f.button :submit

View File

@ -9,6 +9,10 @@
%p
%b Is public:
= @doodad.is_public
%p
%b Is global:
= @doodad.is_global
= link_to 'Edit', edit_doodad_path(@doodad) if policy(@doodad).edit?
\|

View File

@ -4,3 +4,6 @@
%h3 Tokens
- @footer_tokens.each do |token|
= link_to token.name, token
.global-doodads
%h1 Global Doodads
= render @global_doodads

View File

@ -0,0 +1,5 @@
class AddIsGlobalToDoodads < ActiveRecord::Migration[6.1]
def change
add_column :doodads, :is_global, :boolean, default: false
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_11_21_150256) do
ActiveRecord::Schema.define(version: 2023_11_22_115709) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -30,6 +30,7 @@ ActiveRecord::Schema.define(version: 2023_11_21_150256) do
t.boolean "is_public"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "is_global", default: false
t.index ["user_id"], name: "index_doodads_on_user_id"
end