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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With