`
CaiDeHen
  • 浏览: 90559 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

#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." %>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics