Class: RailsAgents::ConnectController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RailsAgents::ConnectController
- Defined in:
- app/controllers/rails_agents/connect_controller.rb
Instance Method Summary collapse
-
#show ⇒ Object
GET /agents/connect?code=… — finishes cloud signup/signin for this Rails app.
Instance Method Details
#show ⇒ Object
GET /agents/connect?code=… — finishes cloud signup/signin for this Rails app.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/rails_agents/connect_controller.rb', line 8 def show code = params[:code].to_s.strip if code.blank? redirect_to rails_agents.root_path, alert: "Missing connect code. Sign up or sign in again." return end response = Client.new.claim_connect(code) data = response["data"] || response api_key = data["apiKey"] || data["api_key"] project_id = data["projectId"] || data["project_id"] = data["embedToken"] || data["embed_token"] raise Client::Error.new("No API key returned") if api_key.blank? CredentialsWriter.write!(api_key: api_key, project_id: project_id) RailsAgents.configure do |config| config.api_key = api_key config.project_id = project_id if project_id end session[:ra_embed_token] = if .present? redirect_to rails_agents.dashboard_path, notice: "Connected to Rails Agent Cloud." rescue Client::Error => e flash[:alert] = e. redirect_to rails_agents.root_path end |