#92 make_resourceful

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.
# products_controller.rb
make_resourceful do
actions :all

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

private

def current_objects
Product.find(:all, :order => '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." %>
發佈了108 篇原創文章 · 獲贊 0 · 訪問量 2925
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章