Skip to content
Snippets Groups Projects
Commit aed7c67d authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

Merge branch 'contacts-model' into 'master'

create model, controller and serializer to contacts form

See merge request !359
parents a320ea57 2e24f690
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