Class: Cardboard::PagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Cardboard::PagesController
- Defined in:
- app/controllers/cardboard/pages_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/cardboard/pages_controller.rb', line 16 def create @page = Cardboard::Page.new(params.require(:page).permit(:title, :template_id)) @page.identifier = @page.title.to_url.underscore if @page.identifier.blank? if @page.save Cardboard::Seed.populate_parts(@page.template.fields, @page) @page.reload redirect_to edit_page_path(@page) else @page.errors.add(:title, "is reserved or is already used") if @page.errors[:identifier].present? render :new end end |
#destroy ⇒ Object
45 46 47 48 49 |
# File 'app/controllers/cardboard/pages_controller.rb', line 45 def destroy @page = Cardboard::Page.find(params[:id]) @page.destroy redirect_to pages_path end |
#edit ⇒ Object
12 13 14 |
# File 'app/controllers/cardboard/pages_controller.rb', line 12 def edit @page = Cardboard::Page.find(params[:id]) end |
#new ⇒ Object
8 9 10 |
# File 'app/controllers/cardboard/pages_controller.rb', line 8 def new @page = Cardboard::Page.new end |
#sort ⇒ Object
40 41 42 43 |
# File 'app/controllers/cardboard/pages_controller.rb', line 40 def sort Cardboard::Page.find(params[:id]).update_attribute(:position_position, params[:index]) render nothing: true end |
#update ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/cardboard/pages_controller.rb', line 29 def update @page = Cardboard::Page.find(params[:id]) if @page.update_attributes(strong_params[:page]) flash[:success] = "Your page was updated successfully" redirect_to edit_page_path(@page) else render :edit end end |