Merge ae1f292719 into 08e5f10559
This commit is contained in:
commit
cba845e99d
14 changed files with 144 additions and 3 deletions
40
app/controllers/organizations_controller.rb
Normal file
40
app/controllers/organizations_controller.rb
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
class OrganizationsController < ApplicationController
|
||||
load_and_authorize_resource :organization
|
||||
|
||||
def index
|
||||
@organizations = Organization.all
|
||||
end
|
||||
|
||||
def create
|
||||
@organization = Organization.new(organization_params)
|
||||
if @organization.save
|
||||
redirect_to organizations_path,
|
||||
notice: 'Organization successfully created'
|
||||
else
|
||||
redirect_to new_organization_path,
|
||||
error: @organization.errors.full_messages.join(', ')
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@organization = Organization.new
|
||||
end
|
||||
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
if @organization.update_attributes(organization_params)
|
||||
redirect_to organizations_path,
|
||||
notice: 'Organization successfully updated'
|
||||
else
|
||||
redirect_to edit_organization_path(@organization),
|
||||
error: @organization.errors.full_messages.join(', ')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def organization_params
|
||||
params.require(:organization).permit(:name, :description, :picture)
|
||||
end
|
||||
end
|
||||
|
|
@ -7,6 +7,8 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
default_scope { order('start_date DESC') }
|
||||
|
||||
belongs_to :organization
|
||||
|
||||
has_paper_trail ignore: %i(updated_at guid revision events_per_week), meta: { conference_id: :id }
|
||||
|
||||
has_and_belongs_to_many :questions
|
||||
|
|
@ -53,7 +55,8 @@ class Conference < ActiveRecord::Base
|
|||
:start_date,
|
||||
:end_date,
|
||||
:start_hour,
|
||||
:end_hour, presence: true
|
||||
:end_hour,
|
||||
:organization, presence: true
|
||||
|
||||
validates :short_title, uniqueness: true
|
||||
validates :short_title, format: { with: /\A[a-zA-Z0-9_-]*\z/ }
|
||||
|
|
|
|||
7
app/models/organization.rb
Normal file
7
app/models/organization.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Organization < ActiveRecord::Base
|
||||
has_many :conferences, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
mount_uploader :picture, PictureUploader, mount_on: :picture
|
||||
end
|
||||
13
app/views/organizations/_form.html.haml
Normal file
13
app/views/organizations/_form.html.haml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
= semantic_form_for(@organization) do |f|
|
||||
= f.inputs name: 'Organization details' do
|
||||
= f.input :name, as: :string, required: true
|
||||
= f.input :description, input_html: { rows: 5 }, placeholder: 'Decribe about your organization..'
|
||||
= image_tag f.object.picture.thumb.url if f.object.picture?
|
||||
- if @organization.picture
|
||||
= image_tag(@organization.picture.thumb.url, width: '20%')
|
||||
= f.input :picture
|
||||
%p.text-right
|
||||
- if @organization.new_record?
|
||||
= f.submit 'Create Organization', class: 'btn btn-success'
|
||||
- else
|
||||
= f.submit 'Update Organization', class: 'btn btn-success'
|
||||
4
app/views/organizations/edit.html.haml
Normal file
4
app/views/organizations/edit.html.haml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.container
|
||||
.row
|
||||
.col-md-12
|
||||
= render 'form'
|
||||
17
app/views/organizations/index.html.haml
Normal file
17
app/views/organizations/index.html.haml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
.container
|
||||
.row
|
||||
.col-md-12.page-header
|
||||
%h1
|
||||
Organizations
|
||||
.btn-group.pull-right
|
||||
= link_to 'Add new', new_organization_path, class: 'btn btn-mini btn-success'
|
||||
- @organizations.each do |organization|
|
||||
.col-md-4
|
||||
.thumbnail
|
||||
= image_tag(organization.picture.thumb.url, width: '20%')
|
||||
.caption
|
||||
%h4
|
||||
= organization.name
|
||||
%button.btn.btn-success Know More
|
||||
= link_to 'Edit', edit_organization_path(organization), class: 'btn btn-mini btn-default'
|
||||
|
||||
4
app/views/organizations/new.html.haml
Normal file
4
app/views/organizations/new.html.haml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.container
|
||||
.row
|
||||
.col-md-12
|
||||
= render 'form'
|
||||
Loading…
Add table
Add a link
Reference in a new issue