6

I have just started using InheritedResources for an application I'm building and when I looked at its Github page, it says it's deprecated, and that I should instead use Responders.

I am new to InheritedResources and Responders so I am confused, how can I get from Responders what I get in InheritedResources (complete REST actions base "template" code) when all I see from the documentation are FlashResponders and HTTPCacheResponders?

I have also taken a look at this one:

http://blog.plataformatec.com.br/tag/inherited_resources/

so does that mean that no more "REST template code" for me?

1 Answer 1

10

The combination of respond_with (which is built in to Rails) in conjunction with the responders gem makes InheritedResources deprecated.

Please have a look at this blog post for an excellent explanation and demonstration of how to create a RESTful controller using respond_with. Most of the controller actions are reduced to single lines of code; with InheritedResources it was possible to have a controller with no code (because it was hidden away in the gem), but Jose Valim (creator of InheritedResources) thought this was too obfuscated as per his quote:

"I have found that the responders abstraction and custom Rails generators offer the perfect balance between hiding and showing too much logic."

The responders come into play if you want to automate any other parts of the controller action, for example, setting the flash messages.


UPDATE: For the commenter below who asked about the destroy action

def destroy
  record = Record.find(params[:id])
  flash[:notice] = "The record has been destroyed successfully" if record.destroy
  respond_with record
end
1
  • The responders gem provides FlashResponder which will set the appropriate flash messages for create, update, and destroy. @fringd
    – graywh
    Commented Nov 28, 2012 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.