Implements Contacts
This commit is contained in:
parent
4955b2b7b8
commit
eb3e6898d2
9 changed files with 156 additions and 5 deletions
43
app/controllers/admin/contacts_controller.rb
Normal file
43
app/controllers/admin/contacts_controller.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
class Admin::ContactsController < ApplicationController
|
||||
before_action :set_conference
|
||||
before_action :set_contact, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /:conference/contact
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /:conference/contact/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# PATCH/PUT /:conference/contact
|
||||
def update
|
||||
if @contact.update(contact_params)
|
||||
redirect_to admin_conference_contact_path, notice: 'Contact details were successfully updated.'
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /:conference/contact
|
||||
def destroy
|
||||
@contact.destroy
|
||||
redirect_to admin_conference_contacts_url, notice: 'Contact details were successfully destroyed.'
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_contact
|
||||
@contact = @conference.contact
|
||||
end
|
||||
|
||||
def set_conference
|
||||
@conference = Conference.find_by(short_title: params[:conference_id])
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def contact_params
|
||||
# params.require(:contact).permit(:social_tag, :email, :facebook, :googleplus, :twitter, :instagram, :public)
|
||||
params[:contact]
|
||||
end
|
||||
end
|
||||
|
|
@ -27,6 +27,8 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
has_and_belongs_to_many :questions
|
||||
|
||||
has_one :contact, dependent: :destroy
|
||||
|
||||
has_one :email_settings, dependent: :destroy
|
||||
has_one :call_for_papers, dependent: :destroy
|
||||
has_many :social_events, dependent: :destroy
|
||||
|
|
@ -523,6 +525,10 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
private
|
||||
|
||||
after_create do
|
||||
self.create_contact
|
||||
end
|
||||
|
||||
##
|
||||
# Calculates the weeks from a start and a end week.
|
||||
#
|
||||
|
|
|
|||
8
app/models/contact.rb
Normal file
8
app/models/contact.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
attr_accessible :conference, :social_tag, :email, :facebook, :googleplus, :twitter, :instagram, :public
|
||||
belongs_to :conference
|
||||
|
||||
validates :conference, presence: true
|
||||
# Conferences only have one contact
|
||||
validates :conference_id, :uniqueness => {:message => "has already contact details"}
|
||||
end
|
||||
31
app/views/admin/contacts/_form.html.haml
Normal file
31
app/views/admin/contacts/_form.html.haml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
= form_for @contact, url: admin_conference_contact_path do |f|
|
||||
- if @contact.errors.any?
|
||||
#error_explanation
|
||||
%h2= "#{pluralize(@contact.errors.count, "error")} prohibited this contact from being saved:"
|
||||
%ul
|
||||
- @contact.errors.full_messages.each do |msg|
|
||||
%li= msg
|
||||
|
||||
.field
|
||||
= f.label :social_tag
|
||||
= f.text_field :social_tag
|
||||
.field
|
||||
= f.label :email
|
||||
= f.text_field :email
|
||||
.field
|
||||
= f.label :facebook
|
||||
= f.text_field :facebook
|
||||
.field
|
||||
= f.label :googleplus
|
||||
= f.text_field :googleplus
|
||||
.field
|
||||
= f.label :twitter
|
||||
= f.text_field :twitter
|
||||
.field
|
||||
= f.label :instagram
|
||||
= f.text_field :instagram
|
||||
.field
|
||||
= f.label :public
|
||||
= f.check_box :public
|
||||
.actions
|
||||
= f.submit 'Save'
|
||||
5
app/views/admin/contacts/edit.html.haml
Normal file
5
app/views/admin/contacts/edit.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
%h1 Editing contact
|
||||
|
||||
= render 'form'
|
||||
|
||||
= link_to 'Back', admin_conference_contact_path
|
||||
26
app/views/admin/contacts/show.html.haml
Normal file
26
app/views/admin/contacts/show.html.haml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
%p#notice= notice
|
||||
|
||||
%p
|
||||
%b Social tag:
|
||||
= @contact.social_tag
|
||||
%p
|
||||
%b Email:
|
||||
= @contact.email
|
||||
%p
|
||||
%b Facebook:
|
||||
= @contact.facebook
|
||||
%p
|
||||
%b Googleplus:
|
||||
= @contact.googleplus
|
||||
%p
|
||||
%b Twitter:
|
||||
= @contact.twitter
|
||||
%p
|
||||
%b Instagram:
|
||||
= @contact.instagram
|
||||
%p
|
||||
%b Public:
|
||||
= @contact.public
|
||||
|
||||
= link_to 'Edit', edit_admin_conference_contact_path
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue