Skip to content

Instantly share code, notes, and snippets.

@ckib16
Created June 3, 2015 21:58
Show Gist options
  • Save ckib16/a00cb35b1669add96b9b to your computer and use it in GitHub Desktop.
Save ckib16/a00cb35b1669add96b9b to your computer and use it in GitHub Desktop.
My API events controller
class API::EventsController < ApplicationController
# Skip CSRF protection in development
skip_before_action :verify_authenticity_token
def create
registered_application = RegisteredApplication.find_by(url: request.env['HTTP_ORIGIN'])
if registered_application = nil
render json: "Unregistered application", status: :unprocessable_entity
end
@event = registered_application.events.build(event_params)
if @event.save
render json: @event, status: :created
else
render @event.errors, status: :unprocessable_entity
end
end
private
def event_params
params.require(:event).permit(:name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment