Rails 3:在Rails中使用JSON响应REST-ful *** 作的正确方法是什么?

Rails 3:在Rails中使用JSON响应REST-ful *** 作的正确方法是什么?,第1张

Rails 3:在Rails中使用JSON响应REST-ful *** 作的正确方法是什么?
#config/routes.rbMyApplicationsName::Application.routes.draw do  resources :articlesend#app/controllers/articles_controller.rbclass ArticlesController < ActionController::base  # so that respond_with knows which formats are  # allowed in each of the individual actions  respond_to :json  def index    @articles = Article.all    respond_with @articles  end  def show    @article = Article.find(params[:id])    respond_with @article  end  ...  def update    @article = Article.find(params[:id])    @article.update_attributes(params[:article])    # respond_with will automatically check @article.valid?    # and respond appropriately ... @article.valid? will    # be set based on whether @article.update_attributes    # succeeded past all the validations    # if @article.valid? then respond_with will redirect to    # to the show page; if !@article.valid? then respond_with    # will show the :edit view, including @article.errors    respond_with @article  end  ...end


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5622943.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存