#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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)