Class: Meroku::AppsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/meroku/apps_controller.rb

Instance Method Summary collapse

Instance Method Details

#additional_env_varsObject

POST /?



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/meroku/apps_controller.rb', line 85

def additional_env_vars
  if params[:dbtype] == "mysql"
    database_url = %Q[export DATABASE_URL=mysql2://u#{@user.id}:#{@user.database_password}@localhost/#{@app_.name}?socket=/opt/bitnami/mysql/tmp/mysql.sock]
  else
    database_url = %Q[export DATABASE_URL=postgres://u#{@user.id}:#{@user.database_password}@localhost/#{@app_.name}]
  end

  respond_to do |format|
    Rails.logger.debug "DB8 #{"export RAILS_ENV=production export PORT=#{3000+@app_.id} #{database_url}"}"
    format.json { render json: { :data => "export RAILS_ENV=production export PORT=#{3000+@app_.id} #{database_url} "}  }
  end
end

#createObject

GET /apps GET /apps.json def index

@apps = App.all

end

GET /apps/1 GET /apps/1.json def show end

GET /apps/new def new

@app = App.new

end

GET /apps/1/edit def edit end

POST /apps POST /apps.json



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/meroku/apps_controller.rb', line 30

def create
  @app = Meroku::App.new(app_params)
  app_saved = @app.save
  collaborator_saved = nil
  if app_saved
    @collaborator = Meroku::App::Collaborator.new(
      app_id: @app.id,
      user_id: @user.id
    )
    collaborator_saved = @collaborator.save
    Meroku::Util.nginx_rebuild()
  end

  respond_to do |format|
    if app_saved && collaborator_saved
      format.json { render json: @app }
    else
      format.json {
        if @app.errors
          render json: { :errors => @app.errors }, :status => :unprocessable_entity
        elsif @collaborator.errors
          render json: { :errors => @collaborator.errors }, :status => :unprocessable_entity
        end
      }
    end
  end
end

#updateObject

PATCH/PUT /apps/1 PATCH/PUT /apps/1.json



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/meroku/apps_controller.rb', line 60

def update
  respond_to do |format|
    if @app_.update(app_params)
      format.json {
        Meroku::Util.nginx_rebuild()
        render json: @app_
      }
    else
      format.json { render json: @app_.errors, status: :unprocessable_entity }
    end
  end
end