forked from fixin.me/fixin.me
Add web-based installation wizard
Replace the CLI-only setup (db:seed + manual application.rb edits) with a web wizard shown automatically on first visit when no admin account exists yet. SetupController (GET/POST /setup) collects the admin e-mail and password, a "skip e-mail confirmation" toggle, and an option to seed the built-in default units. Once submitted it creates the admin User, persists the chosen options as Setting records, and redirects to the sign-in page. ApplicationController gains a redirect_to_setup_if_needed before_action that catches every request (including Devise routes) when no admin exists, so a fresh installation always lands on the wizard rather than an empty sign-in form. A new Setting model provides a lightweight key-value store for runtime options that were previously hard-coded in application.rb (e.g. skip_email_confirmation). RegistrationsController now reads that flag from the database instead of from the application config. Seeds.rb is kept for headless / automated deployments and skips admin creation when an admin already exists (idempotent), with a comment pointing to the web wizard as the preferred path. Also extends the SQLite nil-limit fix (|| Float::INFINITY) to the Quantity model, which suffered the same ArgumentError as Unit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,8 +15,8 @@ class Quantity < ApplicationRecord
|
||||
errors.add(:parent, :descendant_reference) if ancestor_of?(parent)
|
||||
end
|
||||
validates :name, presence: true, uniqueness: {scope: [:user_id, :parent_id]},
|
||||
length: {maximum: type_for_attribute(:name).limit}
|
||||
validates :description, length: {maximum: type_for_attribute(:description).limit}
|
||||
length: {maximum: type_for_attribute(:name).limit || Float::INFINITY}
|
||||
validates :description, length: {maximum: type_for_attribute(:description).limit || Float::INFINITY}
|
||||
|
||||
# Update :depths of progenies after parent change
|
||||
before_save if: :parent_changed? do
|
||||
|
||||
20
app/models/setting.rb
Normal file
20
app/models/setting.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
# Key-value store for runtime application settings that are configured through
|
||||
# the web setup wizard (or updated by an administrator) rather than hard-coded
|
||||
# in application.rb.
|
||||
#
|
||||
# Known keys:
|
||||
# skip_email_confirmation – "true"/"false", mirrors the homonymous option
|
||||
# that was previously in application.rb.
|
||||
class Setting < ApplicationRecord
|
||||
validates :key, presence: true, uniqueness: true
|
||||
|
||||
# Return the string value stored for +key+, or +default+ when absent.
|
||||
def self.get(key, default: nil)
|
||||
find_by(key: key)&.value || default
|
||||
end
|
||||
|
||||
# Persist +value+ for +key+, creating the record if it does not yet exist.
|
||||
def self.set(key, value)
|
||||
find_or_initialize_by(key: key).update!(value: value.to_s)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user