access entries of a content type from the API

This commit is contained in:
did 2012-01-24 21:33:34 +01:00
parent ab507dc165
commit e523cb952c
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,37 @@
module Locomotive
module Api
class ContentEntriesController < BaseController
before_filter :set_content_type
def index
@content_entries = @content_type.list_or_group_entries
respond_with @content_entries
end
def create
@content_entry = @content_type.entries.create(params[:content_entry])
respond_with @content_entry, :location => edit_locomotive_api_content_entry_url(@content_type.slug, @content_entry._id)
end
def update
@content_entry = @content_type.entries.find(params[:id])
@content_entry.update_attributes(params[:content_entry])
respond_with @content_entry, :location => edit_locomotive_api_content_entry_url(@content_type.slug, @content_entry._id)
end
def destroy
@content_entry = @content_type.entries.find(params[:id])
@content_entry.destroy
respond_with @content_entry, :location => locomotive_api_content_entries_url(@content_type.slug)
end
protected
def set_content_type
@content_type ||= current_site.content_types.where(:slug => params[:slug]).first
end
end
end
end

View File

@ -74,6 +74,8 @@ Rails.application.routes.draw do
resources :content_types
resources :content_entries, :path => 'content_types/:slug/entries'
end
end