0

I'm trying to develop some conventions behind our controller responses. One of my conventions is:

On successful create, if the request is XHR, render @the_object

I can't see anything that allows me to do this across the board. Currently I'm doing this:

def create
  create! do |success, failure|
    success.html {
      render @the_object if request.xhr?
    }
  end
end

It's obviously not ideal to have to do this for each controller. Does anyone know if I can create site-wide configurable responses?

brad
  • 31,987
  • 28
  • 102
  • 155
  • create a method in your application controller to do this ? – Awea Jun 03 '11 at 15:25
  • haven't tried that... but inherited_resources inherits from ApplicationController, so won't its methods override this? – brad Jun 03 '11 at 15:44

1 Answers1

0

May be can help you :

# coding: utf-8
class CatsController < ApplicationController
    before_filter :authorize_admin
    inherit_resources #Permet d'utiliser la gem inherit ressources
    def create
        create!(:notice => "Catégorie ajouté avec succès") { {:controller => 'cats' }}
    end
end

Write your method in the ApplicationController and ... :) Or tell me if i'm wrong, i'm not too good in english and beginner in rails

Awea
  • 3,163
  • 8
  • 40
  • 59