Class: Databasium::ModelsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Databasium::ModelsController
- Includes:
- Pagy::Method
- Defined in:
- app/controllers/databasium/models_controller.rb
Constant Summary collapse
- MODEL_TEMPLATE_PATH =
Databasium::Engine.root.join("lib/databasium/templates/model.rb.tt")
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/controllers/databasium/models_controller.rb', line 44 def create content = generate_model_content if params[:commit] == "Create model file" if write_file(content) render turbo_stream: turbo_stream.replace( "flash", Components::Databasium::Global::Flash.new( success: "Model file created successfully, be sure to create a migration for this model if you haven't already" ) ) end else respond_to do |format| format.html format.turbo_stream do render turbo_stream: turbo_stream.replace( "model_preview", Components::Databasium::Models::ModelPreview.new(content: content) ) end end end end |
#new ⇒ Object
6 7 8 9 10 |
# File 'app/controllers/databasium/models_controller.rb', line 6 def new models = @model_service.get_all_models_from_db(search: params[:search]) render Views::Databasium::Models::New.new(content: nil, models: models) end |
#show ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/databasium/models_controller.rb', line 12 def show model = params[:id] content = @model_service.read_model_file(model) attributes = @model_service.get_model_data_from_file(model) models = @model_service.get_all_models_from_db(search: params[:search]) respond_to do |format| format.html do render Views::Databasium::Models::New.new( content: content, model: model, attributes: attributes, models: models ) end format.turbo_stream do render turbo_stream: turbo_stream.replace( "model_preview", Components::Databasium::Models::ModelPreview.new(content: content) ) end end end |
#sidebar ⇒ Object
37 38 39 40 41 42 |
# File 'app/controllers/databasium/models_controller.rb', line 37 def models = @model_service.get_all_models_from_db(search: params[:search]) pagy, models = pagy(models, limit: 7, root_key: "models") render Components::Databasium::SearchResults::Models.new(models: models, pagy: pagy) end |