make_resourceful for rails

Posted by Bhushan Ahire | Posted in Rails, ruby | Posted on 23-06-2008

0

The make_resourceful plugin is a great way to DRY up the 7 RESTful actions common in most controllers. Learn how to use it in this episode.
Tags:

plugins

Resources

script/plugin install http://svn.hamptoncatlin.com/make_resourceful/tags/make_resourceful
# products_controller.rb
make_resourceful do
actions :all

response_for :show do |format|
format.html
format.xml { render  :x ml => current_object.to_xml }
end
end

private

def current_objects
   Product.find(:all,  :o rder => 'name')
end

def current_object
   @current_object ||= Product.find_by_permalink(params[:id])
end
<!-- edit.html.erb -->
<%= hidden_field_tag '_flash[notice]', "Successfully updated product." %>