Class: Admin::PagesController
- Inherits:
-
ForestController
- Object
- ForestController
- Admin::PagesController
- Defined in:
- app/controllers/admin/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
-
#new ⇒ Object
def show unless @page raise ActionController::RoutingError.new(‘Not Found’) end authorize @page redirect_to edit_admin_page_path(@page) end.
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/admin/pages_controller.rb', line 39 def create @page = Page.new @page respond_to do |format| if @page.update(page_params) format.html { redirect_to edit_admin_page_path(@page), notice: 'Page was successfully created.' } format.json { render :show, status: :created, location: @page } else format.html { render :new } format.json { render json: @page.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'app/controllers/admin/pages_controller.rb', line 68 def destroy @page @page.destroy respond_to do |format| format.html { redirect_to admin_pages_url, notice: 'Page was successfully destroyed.' } format.json { head :no_content } end end |
#edit ⇒ Object
35 36 37 |
# File 'app/controllers/admin/pages_controller.rb', line 35 def edit @page end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/admin/pages_controller.rb', line 9 def index if request.format.json? @pages = apply_scopes(Page).by_title.where.not(id: params[:current_record]).page(params[:page]) else # TODO: fuzzy searching doesn't work properly with page hierarchy @parent_pages = apply_scopes(Page.includes(:immediate_children)).parent_pages.page(params[:page]) @pages = apply_scopes(Page).by_title.page params[:page] end @pages respond_to :html, :json end |
#new ⇒ Object
def show
unless @page
raise ActionController::RoutingError.new('Not Found')
end
@page
redirect_to edit_admin_page_path(@page)
end
30 31 32 33 |
# File 'app/controllers/admin/pages_controller.rb', line 30 def new @page = Page.new @page end |
#update ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/admin/pages_controller.rb', line 54 def update @page respond_to do |format| if @page.update(page_params) format.html { redirect_to edit_admin_page_path(@page), notice: 'Page was successfully updated.' } format.json { render :show, status: :ok, location: @page } else format.html { render :edit } format.json { render json: @page.errors, status: :unprocessable_entity } end end end |