From 9b3d41552d4b3e28630470ab88fc4d28ae42b364 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 16 Jul 2015 19:25:47 +0200 Subject: [PATCH] configures responders gem [#5] --- Gemfile | 2 ++ Gemfile.lock | 18 ++++++++++++++++++ app/controllers/application_controller.rb | 5 +++++ config/locales/responders.en.yml | 12 ++++++++++++ config/locales/responders.es.yml | 10 ++++++++++ lib/application_responder.rb | 8 ++++++++ 6 files changed, 55 insertions(+) create mode 100644 config/locales/responders.en.yml create mode 100644 config/locales/responders.es.yml create mode 100644 lib/application_responder.rb diff --git a/Gemfile b/Gemfile index 476024b38..b7badcff5 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem "responders" + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index 441af5fa2..db96916c6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,12 @@ GEM builder (3.2.2) byebug (5.0.0) columnize (= 0.9.0) + capybara (2.4.4) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -54,6 +60,11 @@ GEM diff-lcs (1.2.5) erubis (2.7.0) execjs (2.5.2) + factory_girl (4.5.0) + activesupport (>= 3.0.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) + railties (>= 3.0.0) globalid (0.3.5) activesupport (>= 4.1.0) i18n (0.7.0) @@ -104,6 +115,8 @@ GEM thor (>= 0.18.1, < 2.0) rake (10.4.2) rdoc (4.2.0) + responders (2.1.0) + railties (>= 4.2.0, < 5) rspec-core (3.3.1) rspec-support (~> 3.3.0) rspec-expectations (3.3.0) @@ -154,16 +167,21 @@ GEM binding_of_caller (>= 0.7.2) railties (>= 4.0) sprockets-rails (>= 2.0, < 4.0) + xpath (2.0.0) + nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES byebug + capybara coffee-rails (~> 4.1.0) + factory_girl_rails jbuilder (~> 2.0) jquery-rails rails (= 4.2.3) + responders rspec-rails (~> 3.0) sass-rails (~> 5.0) sdoc (~> 0.4.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e1b..b64f11bb4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,9 @@ +require "application_responder" + class ApplicationController < ActionController::Base + self.responder = ApplicationResponder + respond_to :html + # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception diff --git a/config/locales/responders.en.yml b/config/locales/responders.en.yml new file mode 100644 index 000000000..c3e147abf --- /dev/null +++ b/config/locales/responders.en.yml @@ -0,0 +1,12 @@ +en: + flash: + actions: + create: + notice: '%{resource_name} was successfully created.' + # alert: '%{resource_name} could not be created.' + update: + notice: '%{resource_name} was successfully updated.' + # alert: '%{resource_name} could not be updated.' + destroy: + notice: '%{resource_name} was successfully destroyed.' + alert: '%{resource_name} could not be destroyed.' diff --git a/config/locales/responders.es.yml b/config/locales/responders.es.yml new file mode 100644 index 000000000..aa3a47f0d --- /dev/null +++ b/config/locales/responders.es.yml @@ -0,0 +1,10 @@ +es: + flash: + actions: + create: + notice: "%{resource_name} creado correctamente." + update: + notice: "%{resource_name} actualizado correctamente." + destroy: + notice: "%{resource_name} borrado correctamente." + alert: "%{resource_name} no ha podido ser borrado." \ No newline at end of file diff --git a/lib/application_responder.rb b/lib/application_responder.rb new file mode 100644 index 000000000..cc3e58885 --- /dev/null +++ b/lib/application_responder.rb @@ -0,0 +1,8 @@ +class ApplicationResponder < ActionController::Responder + include Responders::FlashResponder + include Responders::HttpCacheResponder + + # Redirects resources to the collection path (index action) instead + # of the resource path (show action) for POST/PUT/DELETE requests. + # include Responders::CollectionResponder +end