mirror of
https://github.com/danbee/danbarberphoto
synced 2025-03-04 08:49:07 +00:00
WIP: Refactor all the controller.
This commit is contained in:
parent
489edd2d2c
commit
0888020044
@ -3,13 +3,13 @@ class Admin::AdminController < ApplicationController
|
|||||||
before_filter :authenticate_admin_user!
|
before_filter :authenticate_admin_user!
|
||||||
before_filter :admin_menu
|
before_filter :admin_menu
|
||||||
|
|
||||||
force_ssl :host => APP_CONFIG[:ssl_hostname]
|
force_ssl host: APP_CONFIG[:ssl_hostname]
|
||||||
|
|
||||||
def admin_menu
|
def admin_menu
|
||||||
@admin_menu = { :dashboard => '',
|
@admin_menu = { dashboard: '',
|
||||||
:admin_users => '',
|
admin_users: '',
|
||||||
:categories => '',
|
categories: '',
|
||||||
:photos => '',
|
photos: '',
|
||||||
:pages => '' }
|
pages: '' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -15,14 +15,10 @@ class Admin::AdminUsersController < Admin::AdminController
|
|||||||
def update
|
def update
|
||||||
@admin_user = AdminUser.find(params[:id])
|
@admin_user = AdminUser.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
if @admin_user.update_attributes(permitted_params)
|
||||||
if @admin_user.update_attributes(permitted_params)
|
redirect_to admin_admin_users_path, notice: 'Admin User was successfully updated.'
|
||||||
format.html { redirect_to(admin_admin_users_path, :notice => 'Admin User was successfully updated.') }
|
else
|
||||||
format.xml { head :ok }
|
render :edit
|
||||||
else
|
|
||||||
format.html { render :action => "edit" }
|
|
||||||
format.xml { render :xml => @admin_user.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -31,11 +27,9 @@ class Admin::AdminUsersController < Admin::AdminController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @admin_user.save
|
if @admin_user.save
|
||||||
format.html { redirect_to(admin_admin_users_path, :notice => 'Admin User was successfully added.') }
|
redirect_to admin_admin_users_path, notice: 'Admin User was successfully added.'
|
||||||
format.xml { head :ok }
|
|
||||||
else
|
else
|
||||||
format.html { render :action => "edit" }
|
render :edit
|
||||||
format.xml { render :xml => @admin_user.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -44,10 +38,7 @@ class Admin::AdminUsersController < Admin::AdminController
|
|||||||
@admin_user = AdminUser.find(params[:id])
|
@admin_user = AdminUser.find(params[:id])
|
||||||
@admin_user.destroy
|
@admin_user.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
redirect_to admin_admin_users_path, notice: 'Admin User was deleted.'
|
||||||
format.html { redirect_to(admin_admin_users_path, :notice => 'Admin User was deleted.') }
|
|
||||||
format.xml { head :ok }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Allow the current logged in user to change their password
|
# Allow the current logged in user to change their password
|
||||||
@ -59,8 +50,8 @@ class Admin::AdminUsersController < Admin::AdminController
|
|||||||
@admin_user = current_admin_user
|
@admin_user = current_admin_user
|
||||||
|
|
||||||
if @admin_user.update_with_password(permitted_params)
|
if @admin_user.update_with_password(permitted_params)
|
||||||
sign_in(@admin_user, :bypass => true)
|
sign_in @admin_user, bypass: true
|
||||||
redirect_to admin_dashboard_path, :notice => "Password updated!"
|
redirect_to admin_dashboard_path, notice: "Password updated!"
|
||||||
else
|
else
|
||||||
render :edit_password
|
render :edit_password
|
||||||
end
|
end
|
||||||
|
|||||||
@ -15,39 +15,28 @@ class Admin::CategoriesController < Admin::AdminController
|
|||||||
def update
|
def update
|
||||||
@category = Category.find(params[:id])
|
@category = Category.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
if @category.update_attributes(params[:category])
|
||||||
if @category.update_attributes(params[:category])
|
redirect_to admin_categories_path, notice: 'Category was successfully updated.'
|
||||||
format.html { redirect_to(admin_categories_path, :notice => 'Category was successfully updated.') }
|
else
|
||||||
format.xml { head :ok }
|
render :edit
|
||||||
else
|
|
||||||
format.html { render :action => "edit" }
|
|
||||||
format.xml { render :xml => @category.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@category = Category.new(params[:category])
|
@category = Category.new(params[:category])
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @category.save
|
if @category.save
|
||||||
format.html { redirect_to(admin_categories_path, :notice => 'Category was successfully added.') }
|
redirect_to admin_categories_path, notice: 'Category was successfully added.'
|
||||||
format.xml { head :ok }
|
|
||||||
else
|
else
|
||||||
format.html { render :action => "edit" }
|
render :edit
|
||||||
format.xml { render :xml => @category.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@category = Category.find(params[:id])
|
@category = Category.find(params[:id])
|
||||||
@category.destroy
|
@category.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
redirect_to admin_categories_path, notice: 'Category was deleted.'
|
||||||
format.html { redirect_to(admin_categories_path, :notice => 'Category was deleted.') }
|
|
||||||
format.xml { head :ok }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,7 +2,7 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
|
|||||||
layout "admin/layouts/login"
|
layout "admin/layouts/login"
|
||||||
|
|
||||||
skip_before_filter(:authenticate_user!)
|
skip_before_filter(:authenticate_user!)
|
||||||
# PUT /resource/confirmation
|
|
||||||
def update
|
def update
|
||||||
with_unconfirmed_confirmable do
|
with_unconfirmed_confirmable do
|
||||||
if @confirmable.has_no_password?
|
if @confirmable.has_no_password?
|
||||||
@ -23,7 +23,6 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /resource/confirmation?confirmation_token=abcdef
|
|
||||||
def show
|
def show
|
||||||
with_unconfirmed_confirmable do
|
with_unconfirmed_confirmable do
|
||||||
if @confirmable.has_no_password?
|
if @confirmable.has_no_password?
|
||||||
@ -38,6 +37,7 @@ class Admin::ConfirmationsController < ::Devise::PasswordsController
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def with_unconfirmed_confirmable
|
def with_unconfirmed_confirmable
|
||||||
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
|
@confirmable = AdminUser.find_or_initialize_with_error_by(:confirmation_token, params[:confirmation_token])
|
||||||
if !@confirmable.new_record?
|
if !@confirmable.new_record?
|
||||||
|
|||||||
@ -15,28 +15,20 @@ class Admin::PagesController < Admin::AdminController
|
|||||||
def update
|
def update
|
||||||
@page = Page.find(params[:id])
|
@page = Page.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
if @page.update_attributes(params[:page])
|
||||||
if @page.update_attributes(params[:page])
|
redirect_to admin_pages_path, notice: 'Page was successfully updated.'
|
||||||
format.html { redirect_to(admin_pages_path, :notice => 'Page was successfully updated.') }
|
else
|
||||||
format.xml { head :ok }
|
render :edit
|
||||||
else
|
|
||||||
format.html { render :action => "edit" }
|
|
||||||
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@page = Page.new(params[:page])
|
@page = Page.new(params[:page])
|
||||||
|
|
||||||
respond_to do |format|
|
if @page.save
|
||||||
if @page.save
|
redirect_to admin_pages_path, notice: 'Page was successfully added.'
|
||||||
format.html { redirect_to(admin_pages_path, :notice => 'Page was successfully added.') }
|
else
|
||||||
format.xml { head :ok }
|
render :edit
|
||||||
else
|
|
||||||
format.html { render :action => "edit" }
|
|
||||||
format.xml { render :xml => @page.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -44,10 +36,7 @@ class Admin::PagesController < Admin::AdminController
|
|||||||
@page = Page.find(params[:id])
|
@page = Page.find(params[:id])
|
||||||
@page.destroy
|
@page.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
redirect_to admin_pages_path, notice: 'Page was deleted.'
|
||||||
format.html { redirect_to(admin_pages_path, :notice => 'Page was deleted.') }
|
|
||||||
format.xml { head :ok }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,39 +16,28 @@ class Admin::PhotosController < Admin::AdminController
|
|||||||
def update
|
def update
|
||||||
@photo = Photo.find(params[:id])
|
@photo = Photo.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
if @photo.update_attributes(params[:photo])
|
||||||
if @photo.update_attributes(params[:photo])
|
redirect_to admin_photos_path, notice: 'Photo was successfully updated.'
|
||||||
format.html { redirect_to(admin_photos_path, :notice => 'Photo was successfully updated.') }
|
else
|
||||||
format.xml { head :ok }
|
render :edit
|
||||||
else
|
|
||||||
format.html { render :action => "edit" }
|
|
||||||
format.xml { render :xml => @photo.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@photo = Photo.new(params[:photo])
|
@photo = Photo.new(params[:photo])
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @photo.save
|
if @photo.save
|
||||||
format.html { redirect_to(admin_photos_path, :notice => 'Photo was successfully added.') }
|
redirect_to admin_photos_path, notice: 'Photo was successfully added.'
|
||||||
format.xml { head :ok }
|
|
||||||
else
|
else
|
||||||
format.html { render :action => "edit" }
|
render :edit
|
||||||
format.xml { render :xml => @photo.errors, :status => :unprocessable_entity }
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@photo = Photo.find(params[:id])
|
@photo = Photo.find(params[:id])
|
||||||
@photo.destroy
|
@photo.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
redirect_to admin_photos_path, notice: 'Photo was deleted.'
|
||||||
format.html { redirect_to(admin_photos_path, :notice => 'Photo was deleted.') }
|
|
||||||
format.xml { head :ok }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
|
|
||||||
rescue_from ActiveRecord::RecordNotFound, :with => :render_404
|
rescue_from ActiveRecord::RecordNotFound, with: :render_404
|
||||||
|
|
||||||
def after_sign_in_path_for(resource_or_scope)
|
def after_sign_in_path_for(resource_or_scope)
|
||||||
admin_dashboard_path
|
admin_dashboard_path
|
||||||
@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render_404
|
def render_404
|
||||||
render 'errors/not_found', :status => 404
|
render 'errors/not_found', status: :not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,7 +2,7 @@ class CategoriesController < ApplicationController
|
|||||||
# GET /categories
|
# GET /categories
|
||||||
# GET /categories.xml
|
# GET /categories.xml
|
||||||
def index
|
def index
|
||||||
@categories = Category.order('sort ASC').paginate :page => params[:page], :per_page => 4
|
@categories = Category.order('sort ASC').paginate page: params[:page], per_page: 4
|
||||||
|
|
||||||
@photos = Photo.featured.limit(2).order('RANDOM()')
|
@photos = Photo.featured.limit(2).order('RANDOM()')
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ class CategoriesController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.xml { render :xml => @categories }
|
format.xml { render xml: @categories }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ class CategoriesController < ApplicationController
|
|||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # show.html.erb
|
format.html # show.html.erb
|
||||||
format.xml { render :xml => @category }
|
format.xml { render xml: @category }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
class ContactsController < ApplicationController
|
class ContactsController < ApplicationController
|
||||||
def new
|
def new
|
||||||
@contact = Contact.new(:id => 1)
|
@contact = Contact.new(id: 1)
|
||||||
@page_title = 'Contact'
|
@page_title = 'Contact'
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@contact = Contact.new(params[:contact])
|
@contact = Contact.new(params[:contact])
|
||||||
if @contact.save
|
if @contact.save
|
||||||
redirect_to(:new_contact, :notice => t("contact.thanks"))
|
redirect_to(:new_contact, notice: t("contact.thanks"))
|
||||||
else
|
else
|
||||||
flash[:alert] = t("contact.invalid")
|
flash[:alert] = t("contact.invalid")
|
||||||
render :new
|
render :new
|
||||||
|
|||||||
@ -2,10 +2,10 @@ class PhotosController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
if params[:category_id]
|
if params[:category_id]
|
||||||
@category = Category.find_by_id(params[:category_id])
|
@category = Category.find_by_id(params[:category_id])
|
||||||
@photos = @category.photos.enabled.order{taken_at.desc}.paginate(:page => params[:page], :per_page => 11)
|
@photos = @category.photos.enabled.order{taken_at.desc}.paginate(page: params[:page], per_page: 11)
|
||||||
@page_title = @category.name
|
@page_title = @category.name
|
||||||
else
|
else
|
||||||
@photos = Photo.enabled.order{taken_at.desc}.paginate(:page => params[:page], :per_page => 11)
|
@photos = Photo.enabled.order{taken_at.desc}.paginate(page: params[:page], per_page: 11)
|
||||||
@page_title = 'All Photos'
|
@page_title = 'All Photos'
|
||||||
end
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user