From a674e46c914a5a5ce9668b1f7df73cc700c1f9eb Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Mon, 4 Jan 2010 17:49:55 +0800 Subject: [PATCH] clean up useless code --- app/controllers/admin/layouts_controller.rb | 59 +++++--------------- app/controllers/admin/pages_controller.rb | 57 ++++--------------- app/controllers/admin/snippets_controller.rb | 58 +++++-------------- config/environment.rb | 2 +- 4 files changed, 39 insertions(+), 137 deletions(-) diff --git a/app/controllers/admin/layouts_controller.rb b/app/controllers/admin/layouts_controller.rb index ba857fe5..67cfda2b 100644 --- a/app/controllers/admin/layouts_controller.rb +++ b/app/controllers/admin/layouts_controller.rb @@ -2,84 +2,51 @@ class Admin::LayoutsController < ApplicationController layout "admin" - # GET /layouts - # GET /layouts.xml def index @layouts = Layout.all - - respond_to do |format| - format.html # index.html.erb - format.xml { render :xml => @layouts } - end end - # GET /layouts/1 - # GET /layouts/1.xml def show @layout = Layout.find(params[:id]) redirect_to "/#{@layout.name}" end - # GET /layouts/new - # GET /layouts/new.xml def new @layout = Layout.new - - respond_to do |format| - format.html # new.html.erb - format.xml { render :xml => @layouts } - end end - # GET /layouts/1/edit def edit @layout = Layout.find(params[:id]) end - # POST /layouts - # POST /layouts.xml def create @layout = Layout.new(params[:layout]) - respond_to do |format| - if @layout.save - flash[:notice] = 'Layout was successfully created.' - format.html { redirect_to admin_layouts_url } - format.xml { render :xml => @layout, :status => :created, :location => @layouts } - else - format.html { render :action => "new" } - format.xml { render :xml => @layout.errors, :status => :unprocessable_entity } - end + if @layout.save + flash[:notice] = 'Layout was successfully created.' + redirect_to admin_layouts_url + else + render :action => "new" end end - # PUT /layouts/1 - # PUT /layouts/1.xml def update @layout = Layout.find(params[:id]) - - respond_to do |format| - if @layout.update_attributes(params[:layout]) - flash[:notice] = 'Layout was successfully updated.' - format.html { redirect_to admin_layouts_url } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @layout.errors, :status => :unprocessable_entity } - end + + if @layout.update_attributes(params[:layout]) + flash[:notice] = 'Layout was successfully updated.' + redirect_to admin_layouts_url + else + render :action => "edit" end end - # DELETE /layouts/1 - # DELETE /layouts/1.xml def destroy @layout = Layout.find(params[:id]) @layout.destroy - respond_to do |format| - format.html { redirect_to admin_layouts_url } - format.xml { head :ok } - end + redirect_to admin_layouts_url end + end diff --git a/app/controllers/admin/pages_controller.rb b/app/controllers/admin/pages_controller.rb index 35634aef..a7a9a76f 100644 --- a/app/controllers/admin/pages_controller.rb +++ b/app/controllers/admin/pages_controller.rb @@ -2,86 +2,53 @@ class Admin::PagesController < ApplicationController layout "admin" - # GET /pages - # GET /pages.xml def index @pages = Page.all( :conditions => { :parent_page_id => "root" } ) - - respond_to do |format| - format.html # index.html.erb - format.xml { render :xml => @pages } - end end - # GET /pages/1 - # GET /pages/1.xml def show @page = Page.find(params[:id]) redirect_to "/#{@page.name}" end - # GET /pages/new - # GET /pages/new.xml def new @page = Page.new @page.is_published = true @page.parent_page_id = params[:parent_page_id] - - respond_to do |format| - format.html # new.html.erb - format.xml { render :xml => @pages } - end end - # GET /pages/1/edit def edit @page = Page.find(params[:id]) end - # POST /pages - # POST /pages.xml def create @page = Page.new(params[:page]) - respond_to do |format| - if @page.save - flash[:notice] = 'Page was successfully created.' - format.html { redirect_to admin_pages_url } - format.xml { render :xml => @page, :status => :created, :location => @pages } - else - format.html { render :action => "new" } - format.xml { render :xml => @page.errors, :status => :unprocessable_entity } - end + if @page.save + flash[:notice] = 'Page was successfully created.' + redirect_to admin_pages_url + else + render :action => "new" end end - # PUT /pages/1 - # PUT /pages/1.xml def update @page = Page.find(params[:id]) - respond_to do |format| - if @page.update_attributes(params[:page]) - flash[:notice] = 'Page was successfully updated.' - format.html { redirect_to admin_pages_url } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @page.errors, :status => :unprocessable_entity } - end + if @page.update_attributes(params[:page]) + flash[:notice] = 'Page was successfully updated.' + redirect_to admin_pages_url + else + render :action => "edit" end end - # DELETE /pages/1 - # DELETE /pages/1.xml def destroy @page = Page.find(params[:id]) @page.destroy - respond_to do |format| - format.html { redirect_to admin_pages_url } - format.xml { head :ok } - end + redirect_to admin_pages_url end + end diff --git a/app/controllers/admin/snippets_controller.rb b/app/controllers/admin/snippets_controller.rb index 620bc59e..5678fdbb 100644 --- a/app/controllers/admin/snippets_controller.rb +++ b/app/controllers/admin/snippets_controller.rb @@ -2,27 +2,16 @@ class Admin::SnippetsController < ApplicationController layout "admin" - # GET /snippets - # GET /snippets.xml def index @snippets = Snippet.all - - respond_to do |format| - format.html # index.html.erb - format.xml { render :xml => @snippets } - end end - # GET /snippets/1 - # GET /snippets/1.xml def show @snippet = Snippet.find(params[:id]) redirect_to "/#{@snippet.name}" end - # GET /snippets/new - # GET /snippets/new.xml def new @snippet = Snippet.new @@ -41,61 +30,40 @@ class Admin::SnippetsController < ApplicationController end end - - respond_to do |format| - format.html # new.html.erb - format.xml { render :xml => @snippets } - end + end - # GET /snippets/1/edit def edit @snippet = Snippet.find(params[:id]) end - # POST /snippets - # POST /snippets.xml def create @snippet = Snippet.new(params[:snippet]) - respond_to do |format| - if @snippet.save - flash[:notice] = 'Snippet was successfully created.' - format.html { redirect_to admin_snippets_url } - format.xml { render :xml => @snippet, :status => :created, :location => @snippets } - else - format.html { render :action => "new" } - format.xml { render :xml => @snippet.errors, :status => :unprocessable_entity } - end + if @snippet.save + flash[:notice] = 'Snippet was successfully created.' + redirect_to admin_snippets_url + else + render :action => "new" end end - # PUT /snippets/1 - # PUT /snippets/1.xml def update @snippet = Snippet.find(params[:id]) - respond_to do |format| - if @snippet.update_attributes(params[:snippet]) - flash[:notice] = 'Snippet was successfully updated.' - format.html { redirect_to admin_snippets_url } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @snippet.errors, :status => :unprocessable_entity } - end + if @snippet.update_attributes(params[:snippet]) + flash[:notice] = 'Snippet was successfully updated.' + redirect_to admin_snippets_url + else + render :action => "edit" end end - # DELETE /snippets/1 - # DELETE /snippets/1.xml def destroy @snippet = Snippet.find(params[:id]) @snippet.destroy - respond_to do |format| - format.html { redirect_to admin_snippets_url } - format.xml { head :ok } - end + redirect_to admin_snippets_url end + end diff --git a/config/environment.rb b/config/environment.rb index b6e1eb4d..36f570ec 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -29,7 +29,7 @@ Rails::Initializer.run do |config| # Skip frameworks you're not going to use. To use Rails without a database, # you must remove the Active Record framework. - # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] + config.frameworks -= [ :active_record ] # Activate observers that should always be running # config.active_record.observers = :cacher, :garbage_collector, :forum_observer