suggested changes

This commit is contained in:
shlok007 2017-06-05 11:56:47 +05:30
parent 8edf896d86
commit e0d8e85808
11 changed files with 51 additions and 81 deletions

View file

@ -6,6 +6,33 @@ module Admin
@organizations = Organization.all @organizations = Organization.all
end end
def create
@organization = Organization.new(organization_params)
if @organization.save
redirect_to admin_organizations_path,
notice: 'Organization successfully created'
else
redirect_to new_admin_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 admin_organizations_path,
notice: 'Organization successfully updated'
else
redirect_to edit_admin_organization_path(@organization),
error: @organization.errors.full_messages.join(', ')
end
end
def destroy def destroy
if @organization.destroy if @organization.destroy
redirect_to admin_organizations_path, redirect_to admin_organizations_path,
@ -15,5 +42,11 @@ module Admin
error: 'Organization cannot be destroyed' error: 'Organization cannot be destroyed'
end end
end end
private
def organization_params
params.require(:organization).permit(:name, :description, :picture)
end
end end
end end

View file

@ -4,47 +4,4 @@ class OrganizationsController < ApplicationController
def index def index
@organizations = Organization.all @organizations = Organization.all
end 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
def destroy
if @organization.destroy
redirect_to organizations_path,
notice: 'Organization successfully destroyed'
else
redirect_to organizations_path,
error: 'Organization cannot be destroyed'
end
end
private
def organization_params
params.require(:organization).permit(:name, :description, :picture)
end
end end

View file

@ -1,5 +1,5 @@
class Organization < ActiveRecord::Base class Organization < ActiveRecord::Base
has_many :conferences, dependent: :destroy has_many :conferences
validates :name, presence: true validates :name, presence: true

View file

@ -1,7 +1,7 @@
= semantic_form_for(@organization) do |f| = semantic_form_for(@organization, url: (@organization.new_record? ? admin_organizations_path : admin_organization_path(@organization))) do |f|
= f.inputs name: 'Organization details' do = f.inputs name: 'Organization details' do
= f.input :name, as: :string, required: true = f.input :name, as: :string, required: true
= f.input :description, input_html: { rows: 5 }, placeholder: 'Decribe about your organization..' = f.input :description, as: :text, input_html: { rows: 10 }, placeholder: 'Decribe about your organization..'
= image_tag f.object.picture.thumb.url if f.object.picture? = image_tag f.object.picture.thumb.url if f.object.picture?
- if @organization.picture - if @organization.picture
= image_tag(@organization.picture.thumb.url, width: '20%') = image_tag(@organization.picture.thumb.url, width: '20%')
@ -10,4 +10,4 @@
- if @organization.new_record? - if @organization.new_record?
= f.submit 'Create Organization', class: 'btn btn-success' = f.submit 'Create Organization', class: 'btn btn-success'
- else - else
= f.submit 'Update Organization', class: 'btn btn-success' = f.submit 'Update Organization', class: 'btn btn-success'

View file

@ -25,7 +25,7 @@
= organization.conferences.count = organization.conferences.count
%td %td
.btn-group .btn-group
= link_to 'Edit', edit_organization_path(organization), = link_to 'Edit', edit_admin_organization_path(organization),
method: :get, class: 'btn btn-primary' method: :get, class: 'btn btn-primary'
= link_to 'Delete', admin_organization_path(organization), = link_to 'Delete', admin_organization_path(organization),
method: :delete, class: 'btn btn-danger' method: :delete, class: 'btn btn-danger', data: { confirm: "Warning: This will delete #{organization.name} and all its data which includes data for all conferences within #{organization.name}. Do you really want to continue?" }

View file

@ -32,7 +32,8 @@
= link_to(admin_revision_history_path) do = link_to(admin_revision_history_path) do
%span.fa.fa-history %span.fa.fa-history
Revision History Revision History
%li - if ENV['ORGANIZATIONS_ENABLED'] == 'true'
= link_to(admin_organizations_path) do %li
%span.fa.fa-group = link_to(admin_organizations_path) do
Organizations %span.fa.fa-group
Organizations

View file

@ -49,7 +49,8 @@
= link_to(admin_revision_history_path) do = link_to(admin_revision_history_path) do
%span.fa.fa-history %span.fa.fa-history
Revision History Revision History
%li - if ENV['ORGANIZATIONS_ENABLED'] == 'true'
= link_to(admin_organizations_path) do %li
%span.fa.fa-group = link_to(admin_organizations_path) do
Organizations %span.fa.fa-group
Organizations

View file

@ -1,13 +0,0 @@
= 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'

View file

@ -1,4 +0,0 @@
.container
.row
.col-md-12
= render 'form'

View file

@ -4,7 +4,7 @@
%h1 %h1
Organizations Organizations
.btn-group.pull-right .btn-group.pull-right
= link_to 'Add new', new_organization_path, class: 'btn btn-mini btn-success' / = link_to 'Add new', new_organization_path, class: 'btn btn-mini btn-success'
- @organizations.each do |organization| - @organizations.each do |organization|
.col-md-4 .col-md-4
.thumbnail .thumbnail
@ -13,5 +13,4 @@
%h4 %h4
= organization.name = organization.name
%button.btn.btn-success Conferences %button.btn.btn-success Conferences
= link_to 'Edit', edit_organization_path(organization), class: 'btn btn-mini btn-default' / = link_to 'Edit', edit_organization_path(organization), class: 'btn btn-mini btn-default'

View file

@ -1,4 +0,0 @@
.container
.row
.col-md-12
= render 'form'