diff options
author | azul <azul@leap.se> | 2014-07-18 12:21:49 +0200 |
---|---|---|
committer | azul <azul@leap.se> | 2014-07-18 12:21:49 +0200 |
commit | bbd41c9bfd2cb88a88d7436dd58a8b46a5d10cf1 (patch) | |
tree | 00b39da219151473437c02ce35344117bcd5b2fa /app/controllers/controller_extension/json_responses.rb | |
parent | ade74d8a9091ae607586d7b287a0579a2ee7af8e (diff) | |
parent | 20352249fa5dafe3abb2d4b751b1e5c8c0a59abc (diff) |
Merge pull request #180 from azul/feature/messages-api
Feature/messages api
Diffstat (limited to 'app/controllers/controller_extension/json_responses.rb')
-rw-r--r-- | app/controllers/controller_extension/json_responses.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/app/controllers/controller_extension/json_responses.rb b/app/controllers/controller_extension/json_responses.rb new file mode 100644 index 0000000..da1ae58 --- /dev/null +++ b/app/controllers/controller_extension/json_responses.rb @@ -0,0 +1,29 @@ +module ControllerExtension::JsonResponses + extend ActiveSupport::Concern + + private + + def success(key) + json_message :success, key + end + + def error(key) + json_message :error, key + end + + def json_message(type, key) + long_key = "#{controller_string}.#{action_string}.#{key}" + { type => key.to_s, + :message => I18n.t(long_key, cascade: true) } + end + + def controller_string + self.class.name.underscore. + sub(/_controller$/, ''). + sub(/^v\d\//, '') + end + + def action_string + params[:action] + end +end |