Class: Concen::PagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Concen::PagesController
- Defined in:
- app/controllers/concen/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #sort ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/concen/pages_controller.rb', line 18 def create @page = Page.new(params[:concen_page]) @page. = [current_concen_user.username] if @page.save redirect_to(edit_concen_page_path(@page), :notice => "Page was successfully created.") else render :new end end |
#destroy ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/concen/pages_controller.rb', line 49 def destroy if current_concen_user.full_control || @page..include?(current_concen_user) @page = Page.find(params[:id]) @page.destroy redirect_to concen_pages_path else flash[:notice] = "Only author can delete page." redirect_to concen_pages_path end end |
#edit ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/controllers/concen/pages_controller.rb', line 28 def edit @page = Page.find(params[:id]) unless current_concen_user.full_control || @page..include?(current_concen_user) flash[:notice] = "Only author can edit page." redirect_to concen_pages_path end end |
#index ⇒ Object
5 6 7 8 |
# File 'app/controllers/concen/pages_controller.rb', line 5 def index @page_title = "Pages" @page = Page.where(:level => 0).first end |
#new ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/controllers/concen/pages_controller.rb', line 10 def new if params[:parent_id] @page = Page.find(params[:parent_id]).children.build else @page = Page.new end end |
#sort ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/concen/pages_controller.rb', line 60 def sort if params[:page] if current_concen_user.full_control child_count = {} params[:page].each do |key, value| if value == "root" root = Page.find(key) root.parent_id = nil root.level = 0 root.save else child = Page.find(key) parent = Page.find(value) child.parent_id = parent.id child.level = parent.level + 1 if child_count[value] child.position = child_count[value] + 1 child_count[value] += 1 else child.position = 1 child_count[value] = 1 end child.save end end render :json => {:success => true} else render :json => {:success => false, :message => "Only user with full control can sort pages."} end end end |
#update ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/concen/pages_controller.rb', line 36 def update @page = Page.find(params[:id]) if current_concen_user.full_control || @page..include?(current_concen_user) if @page.update_attributes(params[:concen_page]) redirect_to(edit_concen_page_path(@page), :notice => "Page was successfully created.") else render :edit end else render :edit, :notice => "Only author can modify page content." end end |