Class: TinyCMS::PagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- TinyCMS::PagesController
- Defined in:
- lib/tiny_cms/pages_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #reorder ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/tiny_cms/pages_controller.rb', line 26 def create set_resource klass.new(params[resource_name]) if resource.save render :json => resource, :status => :created else render :json => resource.errors, :status => :unprocessable_entity end end |
#destroy ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/tiny_cms/pages_controller.rb', line 61 def destroy set_resource klass.find(params[:id]) resource.destroy respond_to do |format| format.html { redirect_to :controller => params[:controller], :action => 'index'} format.json { render :json => {} } end end |
#edit ⇒ Object
35 36 37 38 |
# File 'lib/tiny_cms/pages_controller.rb', line 35 def edit @page = Page.find params[:id] render 'tiny_cms/edit' end |
#index ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/tiny_cms/pages_controller.rb', line 6 def index respond_to do |format| format.html do @class = klass render 'tiny_cms/index' end format.json { render :json => klass.include_tree(5).roots } end end |
#reorder ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/tiny_cms/pages_controller.rb', line 53 def reorder if klass.reorder params[:page]['child_ids'] render :json => {} else render :json => {}, :status => :unprocessable_entity end end |
#show ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/tiny_cms/pages_controller.rb', line 16 def show if params[:id] set_resource klass.find(params[:id]) else set_resource klass.by_path(params[:path]).first raise ActiveRecord::RecordNotFound if resource.nil? or resource.content.blank? end render 'tiny_cms/show' end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tiny_cms/pages_controller.rb', line 40 def update set_resource klass.find(params[:id]) respond_to do |format| if resource.update_attributes params[resource_name] format.html { redirect_to resource } format.json { render :json => {} } else format.html { render 'tiny_cms/edit' } format.json { render :json => resource.errors, :status => :unprocessable_entity } end end end |