# articles_controller.rb - a sample script for Ruby on Rails # # Copyright (C) 2005-2009 Masao Mutoh # # This file is distributed under the same license as Ruby-GetText-Package. class ArticlesController < ApplicationController # If you want to have textdomains each as controllers. # You need to bind textdomain here. #init_gettext "article" # GET /articles # GET /articles.xml def index list render :action => "list" end def list @articles = Article.find(:all) end # GET /articles/1 # GET /articles/1.xml def show @article = Article.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @article } end end # GET /articles/new # GET /articles/new.xml def new @article = Article.new @article.lastupdate = Date.new(2009, 3, 17) respond_to do |format| format.html # new.html.erb format.xml { render :xml => @article } end end # GET /articles/1/edit def edit @article = Article.find(params[:id]) end # POST /articles # POST /articles.xml def create @article = Article.new(params[:article]) respond_to do |format| if @article.save flash[:notice] = _('Article was successfully created.') format.html { redirect_to(@article) } format.xml { render :xml => @article, :status => :created, :location => @article } else format.html { render :action => "new" } format.xml { render :xml => @article.errors, :status => :unprocessable_entity } end end end # PUT /articles/1 # PUT /articles/1.xml def update @article = Article.find(params[:id]) respond_to do |format| if @article.update_attributes(params[:article]) flash[:notice] = _('Article was successfully updated.') format.html { redirect_to(@article) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @article.errors, :status => :unprocessable_entity } end end end # DELETE /articles/1 # DELETE /articles/1.xml def destroy @article = Article.find(params[:id]) @article.destroy respond_to do |format| format.html { redirect_to(articles_url) } format.xml { head :ok } end end end