Class: Api::ContentsController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::ContentsController
- Defined in:
- app/controllers/alchemy/api/contents_controller.rb
Instance Method Summary collapse
-
#index ⇒ Object
Returns all contents as json object.
-
#show ⇒ Object
Returns a json object for content.
Instance Method Details
#index ⇒ Object
Returns all contents as json object
You can either load all or only these for :element_id param
8 9 10 11 12 13 14 |
# File 'app/controllers/alchemy/api/contents_controller.rb', line 8 def index @contents = Content.accessible_by(current_ability, :index) if params[:element_id].present? @contents = @contents.where(element_id: params[:element_id]) end respond_with @contents end |
#show ⇒ Object
Returns a json object for content
You can either load it from :id param or even more useful via passing the element id and the name of the content
$ bin/rake routes
for more infos on how the url looks like.
25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/alchemy/api/contents_controller.rb', line 25 def show if params[:id] @content = Content.find(params[:id]) elsif params[:element_id] && params[:name] @content = Content.find_by!(element_id: params[:element_id], name: params[:name]) end :show, @content respond_with @content end |