class ArticlesController < ApplicationController respond_to :xlsx, :only => [:index, :another, :empty] # GET /articles # GET /articles.json def index @articles = Article.order('id DESC') respond_to do |format| format.html # index.html.erb format.json { render json: @articles } format.xlsx { render xlsx: @articles } end end def another @articles = Article.order('id DESC') respond_with(@articles) end def empty @articles = [] respond_to do |format| format.json { render json: @articles } format.xlsx { render xlsx: @articles } end end # GET /articles/1 # GET /articles/1.json def show @article = Article.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @article } end end # GET /articles/new # GET /articles/new.json def new @article = Article.new respond_to do |format| format.html # new.html.erb format.json { render json: @article } end end # GET /articles/1/edit def edit @article = Article.find(params[:id]) end # POST /articles # POST /articles.json def create @article = Article.new(params[:article]) respond_to do |format| if @article.save format.html { redirect_to @article, notice: 'Article was successfully created.' } format.json { render json: @article, status: :created, location: @article } else format.html { render action: "new" } format.json { render json: @article.errors, status: :unprocessable_entity } end end end # PUT /articles/1 # PUT /articles/1.json def update @article = Article.find(params[:id]) respond_to do |format| if @article.update_attributes(params[:article]) format.html { redirect_to @article, notice: 'Article was successfully updated.' } format.json { head :ok } else format.html { render action: "edit" } format.json { render json: @article.errors, status: :unprocessable_entity } end end end # DELETE /articles/1 # DELETE /articles/1.json def destroy @article = Article.find(params[:id]) @article.destroy respond_to do |format| format.html { redirect_to articles_url } format.json { head :ok } end end end