Created
June 3, 2015 21:58
-
-
Save ckib16/a00cb35b1669add96b9b to your computer and use it in GitHub Desktop.
My API events controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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