Class: SlashMigrate::ModelsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SlashMigrate::ModelsController
- Defined in:
- app/controllers/slash_migrate/models_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #new ⇒ Object
-
#preview ⇒ Object
Live preview: rebuilds the migration + model source on every (debounced) form change and streams it back.
Instance Method Details
#create ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/slash_migrate/models_controller.rb', line 26 def create builder = build_builder if inspector.exists?(builder.table_name) redirect_to(new_model_path, alert: "A table named #{builder.table_name} already exists.") return end written = builder.write! redirect_to migrations_path, notice: "Created #{written.join(", ")}. Run it below to apply." end |
#new ⇒ Object
3 4 5 6 |
# File 'app/controllers/slash_migrate/models_controller.rb', line 3 def new @builder = MigrationBuilder.new(name: "") @existing_tables = inspector.table_names end |
#preview ⇒ Object
Live preview: rebuilds the migration + model source on every (debounced) form change and streams it back. Pure string building, no disk writes.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/slash_migrate/models_controller.rb', line 10 def preview @builder = build_builder if @builder.name_present? @table_exists = inspector.exists?(@builder.table_name) else @hint = "Enter a model name to see the migration it will generate." end render_stream :preview rescue => e # Partial/invalid input shouldn't 500 the live preview; show the problem. @error = e. render_stream :preview end |