Class: PagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PagesController
- Defined in:
- app/controllers/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #publish ⇒ Object
- #show ⇒ Object
- #sort ⇒ Object
- #toggle_for_blog ⇒ Object
- #unpublish ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/pages_controller.rb', line 26 def create @page = Page.new(page_params) @page. = current_user.id if @page.save redirect_to @page, notice: t('pages.create.notice') else flash[:warning] = t('pages.create.warning') render action: "new", layout: 'admin' end end |
#destroy ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/pages_controller.rb', line 47 def destroy unless params[:id].to_i == 1 @page = Page.find(params[:id]) @page.destroy redirect_to pages_url, notice: t('pages.destroy.notice') else # one should not be able to destroy the page #1 which is the site's home page flash[:warning] = t('pages.destroy.root_warning') redirect_to ( :back || pages_url ) end end |
#edit ⇒ Object
21 22 23 24 |
# File 'app/controllers/pages_controller.rb', line 21 def edit @page = Page.find(params[:id]) switch_to_admin_layout end |
#index ⇒ Object
6 7 8 9 |
# File 'app/controllers/pages_controller.rb', line 6 def index @pages = Page.by_recent.paginate(:page => params[:page], :per_page => 35) switch_to_admin_layout end |
#new ⇒ Object
16 17 18 19 |
# File 'app/controllers/pages_controller.rb', line 16 def new @page = Page.new switch_to_admin_layout end |
#publish ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/pages_controller.rb', line 58 def publish page = Page.find(params[:id]) page.published_at = Time.now if page.save redirect_to pages_path, notice: t('pages.status.changed.published') else redirect_to :back, :flash => { :error => 'There was a problem while publishing this page.' } end end |
#show ⇒ Object
11 12 13 14 |
# File 'app/controllers/pages_controller.rb', line 11 def show @page = Page.find(params[:id]) render layout: 'blog' if @page.for_blog? end |
#sort ⇒ Object
85 86 87 88 89 90 |
# File 'app/controllers/pages_controller.rb', line 85 def sort params[:page].each_with_index do |id, index| Page.update(id, menu_position: index+1) end render nothing: true end |
#toggle_for_blog ⇒ Object
78 79 80 81 82 83 |
# File 'app/controllers/pages_controller.rb', line 78 def toggle_for_blog page = Page.find(params[:id]) page.for_blog? ? page.for_blog = false : page.for_blog = true page.save redirect_to pages_path notice: t('pages.status.changed.toggled') end |
#unpublish ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/pages_controller.rb', line 68 def unpublish page = Page.find(params[:id]) page.published_at = nil if page.save redirect_to pages_path, notice: t('pages.status.changed.unpublished') else redirect_to :back, :flash => { :error => 'There was a problem while unpublishing this page.' } end end |
#update ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/pages_controller.rb', line 37 def update @page = Page.find(params[:id]) if @page.update_attributes(page_params) redirect_to @page, notice: t('pages.update.notice') else flash[:warning] = t('pages.update.warning') render action: "edit", layout: 'admin' end end |