app/controllers/landable/api/templates_controller.rb in landable-1.7.1.rc1 vs app/controllers/landable/api/templates_controller.rb in landable-1.8.0

- old
+ new

@@ -1,39 +1,63 @@ require_dependency "landable/api_controller" module Landable module Api class TemplatesController < ApiController - def index - respond_with Template.all - end + # filters + before_filter :load_template, except: [:create, :index] + # RESTful methods def create template = Template.new(template_params) template.save! + respond_with template, status: :created, location: template_url(template) end + def destroy + @template.temp_author = current_author + @template.try(:deactivate) + + respond_with @template + end + + def index + respond_with Template.all + end + def show - respond_with Template.find(params[:id]) + respond_with @template end def update - template = Template.find(params[:id]) - template.update_attributes! template_params - respond_with template + @template.update_attributes!(template_params) + + respond_with @template end + # custom methods def publish - template = Template.find params[:id] - template.publish! author_id: current_author.id, notes: params[:notes], is_minor: !!params[:is_minor] - respond_with template + @template.publish! author_id: current_author.id, notes: params[:notes], is_minor: !!params[:is_minor] + + respond_with @template end + def reactivate + @template.try(:reactivate) + + respond_with @template + end + private + def load_template + @template = Template.find(params[:id]) + end - def template_params - params.require(:template).permit(:id, :name, :body, :description, :thumbnail_url, :slug, :is_layout, :is_publishable) - end + def template_params + params.require(:template).permit(:id, :name, :body, :description, :thumbnail_url, :slug, :is_layout, :is_publishable) + end + + # end end end end