Class: KeysController
- Inherits:
-
ConsoleController
- Object
- ConsoleController
- KeysController
- Defined in:
- app/controllers/keys_controller.rb
Instance Method Summary collapse
Methods inherited from ConsoleController
Methods included from SshkeyAware
Methods included from DomainAware
#domain_is_missing, #user_default_domain
Methods included from CapabilityAware
Instance Method Details
#create ⇒ Object
7 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 35 36 |
# File 'app/controllers/keys_controller.rb', line 7 def create @first = true if params[:first] @key ||= Key.new params[:key] @key.as = current_user if @key.save redirect_to (@first ? :back : account_path), :flash => {:success => 'Your public key has been created'} rescue redirect_to account_path else Rails.logger.debug @key.errors.inspect render :new end # If a key already exists with that name # FIXME When resource validation is added, we may need the server to return a unique code # for this condition with the error, and then this logic should be moved to Key.rescue_save_failure # which should throw a more specific exception Key::NameExists / Key::ContentExists rescue Key::DuplicateName if @first if @key.default? @key = Key.default(:as => current_user).load(params[:key]) else @key.make_unique! "#{@key.name}%s" end raise if @retried @retried = true retry end @key.errors.add(:name, 'You have already created a key with that name') render :new end |