Module: Lesli::Interfaces::Controllers::Actions
- Defined in:
- app/controllers/lesli/interfaces/controllers/actions.rb
Instance Method Summary collapse
-
#create ⇒ Json
Json that contains wheter the creation of the action was successful or not.
-
#destroy ⇒ Json
A response that contains wheter the action was deleted or not.
-
#index ⇒ Json
Json that contains a list of all actions related to a cloud_object.
-
#show ⇒ JSON
The json information about the selected action.
-
#update ⇒ Json
Json that contains wheter the update of the action was successful or not.
Instance Method Details
#create ⇒ Json
Returns Json that contains wheter the creation of the action was successful or not. If it is not successful, it returs an error message.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 94 def create action_model = action_model() # If there is a custom action model, it must be returned in this method cloud_object_model = action_model.cloud_object_model set_cloud_object new_action_params = action_params.merge( user_creator: current_user ) action = @cloud_object.actions.new(new_action_params) if action.save if block_given? yield(cloud_object, action) else respond_with_successful(action.show(current_user)) end else respond_with_error(action.errors.) end end |
#destroy ⇒ Json
Returns A response that contains wheter the action was deleted or not. If it is not successful, it returns an error message.
150 151 152 153 154 155 156 157 158 159 |
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 150 def destroy set_action return respond_with_not_found unless @action if @action.destroy respond_with_successful else respond_with_error(@action.errors..to_sentence) end end |
#index ⇒ Json
Returns Json that contains a list of all actions related to a cloud_object.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 46 def index set_cloud_object() action_model = action_model() # If there is a custom action model, it must be returned in this method cloud_object_model = action_model.cloud_object_model @actions = action_model.index(current_user, @cloud_object) if block_given? yield(@actions) else respond_with_successful(@actions) end end |
#show ⇒ JSON
Returns The json information about the selected action.
68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 68 def show set_action return respond_with_not_found unless @action if block_given? yield(@action) else return respond_with_successful(@action) end end |
#update ⇒ Json
Returns Json that contains wheter the update of the action was successful or not. If it is not successful, it returs an error message.
130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/controllers/lesli/interfaces/controllers/actions.rb', line 130 def update set_action return respond_with_not_found unless @action return unless @action.is_editable_by?(current_user) if @action.update(action_params) respond_with_successful(@action.show(current_user)) else respond_with_error(@action.errors..to_sentence) end end |