events api
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
ActiveAdmin.register Event do
|
||||
permit_params :name, :date
|
||||
|
||||
menu priority: 3
|
||||
|
||||
index do
|
||||
selectable_column
|
||||
id_column
|
||||
column :name
|
||||
column :date
|
||||
column :created_at
|
||||
actions
|
||||
end
|
||||
|
||||
filter :name
|
||||
filter :date
|
||||
|
||||
show do
|
||||
attributes_table do
|
||||
row :id
|
||||
row :name
|
||||
row :date
|
||||
row :created_at
|
||||
row :updated_at
|
||||
end
|
||||
end
|
||||
|
||||
form do |f|
|
||||
f.inputs do
|
||||
f.input :name
|
||||
f.input :date, as: :date_time_picker
|
||||
end
|
||||
f.actions
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class Api::EventsController < ApiController
|
||||
def index
|
||||
events = Event.upcoming.map do |e|
|
||||
{ name: e.name, date: e.date.utc.strftime("%Y-%m-%dT%H:%M:%SZ") }
|
||||
end
|
||||
render json: events
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class Event < ApplicationRecord
|
||||
default_scope { where(deleted_at: nil) }
|
||||
|
||||
scope :upcoming, -> { where("date > ?", Time.current).order(:date) }
|
||||
|
||||
def self.ransackable_attributes(auth_object = nil)
|
||||
%w[id name date created_at updated_at]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user