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

#95 More on ActiveResource

阅读更多
See how to handle authentication and custom actions using ActiveResource in this episode.
# models/product.rb (in blog app)
class Product < ActiveResource::Base
  self.site = "http://admin:secret@localhost:3000"
end

# script/console (in blog app)
Product.find(:all) # GET products.xml
Product.find(:all, :params => { :search => 'table' }) # GET products.xml?search=table
p = Product.create(:name => 'foo') # POST products.xml
p.name = 'bar'
p.save # PUT products/11.xml
p.destroy # DELETE products/11.xml
Product.get(:recent) # GET products/recent.xml
p = Product.find(1) # GET products/1.xml
p.put(:discontinue) # PUT products/1/discontinue.xml

# routes.rb (in store app)
map.resources :products, :collection => { :recent => :get },
                         :member     => { :discontinue => :put }

# products_controller.rb (in store app)
before_filter :authorize

protected

def authorize
  authenticate_or_request_with_http_basic do |username, password|
    username == "admin" && password == "secret"
  end
end
分享到:
评论

相关推荐

    Apress.More.Joel.on.Software.Jun.2008.pdf

    《More Joel on Software》是Joel Spolsky的著作,由Apress出版社于2008年出版。这本书深入探讨了软件开发、设计与管理领域的多样性和相关问题,旨在为软件开发者、设计师、经理以及与他们合作的人士提供有价值的...

    More Joel on software

    美国著名程序员Joel Spolsky关于软件管理和技术公司管理精辟论述,读来受益匪浅,特别是其中给大学计算机系学生的建议。

    More Joel on Software

    Further Thoughts on Diverse and Occasionally Related Matters That Will Prove of Interest to Software Developers, Designers, and Managers, and to Those Who, Whether by Good Fortune or Ill Luck, Work ...

    ruby on rails 101

    - **核心理念**:“Less is More”,强调简洁和高效。 - **推动者**:Dave Thomas和他的Pragmatic Programmers团队对Ruby on Rails的发展起到了重要的推动作用。 #### 四、Rails简介 Ruby on Rails是一个开源Web...

    More on Multivariate Gaussians

    For Standford CS229. Up to this point in class, you have seen multivariate Gaussians arise in a number of applications, such as the probabilistic ...confidence on your homework (hint hint!) and beyond.

    More Eric Meyer on CSS

    《More Eric Meyer on CSS》是CSS领域的一本经典著作,由知名的前端开发者Eric Meyer撰写。这本书深入探讨了CSS(层叠样式表)的各种高级技术,为读者提供了丰富的实践经验和深入理解CSS的理论基础。 首先,我们...

    Linux-more.txt

    在深入探讨Linux中的`more`命令之前,我们先简要回顾一下`more`的基本功能及其在Linux环境下的重要性。`more`是一个用于查看大文本文件的分页工具,允许用户逐页或逐行地浏览文件内容,尤其适用于查看那些一次性无法...

    进阶课程㉖丨Apollo规划技术详解——Understand More on the MP Difficulty.pdf

    进阶课程㉖丨Apollo规划技术详解——Understand More on the MP Difficulty.pdf

    Attacks on More Virtual Machine Emulators.pdf

    反调试与反反调试内容收集,做反调试的时候收集整理的源文档。准备总结中

    Playful Tagging — Folksonomy Generation Using Online

    ### Playful Tagging — Folksonomy Generation Using Online Games #### Introduction In the digital era, collaborative tagging has emerged as a powerful method to create folksonomies, which are user-...

    learn more study less 英文原版

    ### 《Learn More Study Less》核心知识点概览 #### 标题解读 - **"Learn More Study Less"**:本书的核心理念在于通过高效的学习方法帮助读者在减少学习时间的同时掌握更多的知识。 #### 描述解读 - **尝试改变已...

    On Writing Well 2006 (30th Anniversary Edition)

    "On Writing Well" has been praised for its sound advice, ... With more than a million copies sold, this volume has stood the test of time and remains a valuable resource for writers and would-be writers.

    More Effective Coroutines [PRO] v3.12.0

    Both versions run on the same super-fast core. Switching between MEC coroutines and Unity's default coroutines is really easy. They can even be used side by side in the same project. Advantages of ...

    More Effective C++ 简体中文版(pdf 版).pdf

    ### More Effective C++ 简体中文版(pdf 版).pdf #### 书籍概述 《More Effective C++》是一本由 Scott Meyers 所著的经典著作,旨在帮助程序员更好地掌握 C++ 的高级特性,并有效地应用于实际编程中。本书分为多...

    More Effective C++.pdf

    《More Effective C++》是一本由Scott Meyers撰写的经典C++编程指南,旨在帮助程序员深入理解并高效运用C++的各项特性。该书由台湾著名程序员侯捷翻译并撰写导读,详细介绍了35个C++编程实践中的关键知识点,覆盖了...

    Ajax on Rails

    ### Ajax on Rails:深入理解与应用 随着网络技术的发展,用户对Web应用的交互性和响应速度提出了更高的要求。Ajax(Asynchronous JavaScript and XML)技术的出现为解决这一问题提供了有力的支持。本文将详细介绍...

    DevelopersGuide_MinixOnARM

    ### Minix on ARM: Developers Guide #### Introduction Minix on ARM is a port of the Minix operating system specifically designed for devices based on ARM architecture. The primary targets include the...

    01. Cramming more components onto integrated circuits

    adv computer systems,The future of integrated electronics is the future of electronics itself. The advantages of integration will bring about a ...Computers will be more powerful, and

Global site tag (gtag.js) - Google Analytics