Skip to content
Snippets Groups Projects
Commit 0ed6ca52 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Merge branch 'master' into fix-collection-index

parents ba78b934 aed7c67d
No related branches found
No related tags found
No related merge requests found
class V1::ContactsController < ApplicationController
include ::Paginator
before_action :set_contact, only: [:show, :update, :destroy]
# GET v1/contacts
def index
contacts = paginate Contact
render json: contacts
end
# GET v1/contacts/1
def show
render json: @contact
end
# POST v1/contacts
def create
@contact = Contact.new(contact_params)
if @contact.save
render json: @contact, status: :created
else
render json: @contact.errors, status: :unprocessable_entity
end
end
# PATCH/PUT v1/contacts/1
def update
if @contact.update(contact_params)
render json: @contact
else
render json: @contact.errors, status: :unprocessable_entity
end
end
# DELETE v1/contacts/1
def destroy
@contact.destroy
render status: :ok
end
private
# Use callbacks to share common setup or constraints between actions.
def set_contact
@contact = Contact.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def contact_params
params.require(:contact).permit(:name, :email, :message)
end
end
# == Schema Information
#
# Table name: contacts
#
# id :integer not null, primary key
# name :string
# email :string
# message :text
#
class Contact < ApplicationRecord
end
class ContactSerializer < ActiveModel::Serializer
cache key: 'contact', expires_in: 24.hours
attributes :id, :name, :email, :message
end
......@@ -139,6 +139,7 @@ Rails.application.routes.draw do
resources :roles, except: [:new, :edit]
resources :scores, only: [:index, :show, :update]
resources :ratings, except: [:new, :edit]
resources :contacts
post '/package', to: 'packages#link'
get '/subjects', to: 'subjects#index'
......
class CreateContacts < ActiveRecord::Migration[5.0]
def change
create_table :contacts do |t|
t.string :name
t.string :email
t.text :message
t.timestamps
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment