From e0d8e85808cadb8f708ed991b019a176d1a8bfbb Mon Sep 17 00:00:00 2001 From: shlok007 Date: Mon, 5 Jun 2017 11:56:47 +0530 Subject: [PATCH] suggested changes --- .../admin/organizations_controller.rb | 33 ++++++++++++++ app/controllers/organizations_controller.rb | 43 ------------------- app/models/organization.rb | 2 +- app/views/admin/organizations/_form.html.haml | 6 +-- app/views/admin/organizations/index.html.haml | 4 +- .../layouts/_admin_sidebar_index.html.haml | 9 ++-- app/views/layouts/_user_menu.html.haml | 9 ++-- app/views/organizations/_form.html.haml | 13 ------ app/views/organizations/edit.html.haml | 4 -- app/views/organizations/index.html.haml | 5 +-- app/views/organizations/new.html.haml | 4 -- 11 files changed, 51 insertions(+), 81 deletions(-) delete mode 100644 app/views/organizations/_form.html.haml delete mode 100644 app/views/organizations/edit.html.haml delete mode 100644 app/views/organizations/new.html.haml diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 1dc6bcd5..087bf7f8 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -6,6 +6,33 @@ module Admin @organizations = Organization.all 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 if @organization.destroy redirect_to admin_organizations_path, @@ -15,5 +42,11 @@ module Admin error: 'Organization cannot be destroyed' end end + + private + + def organization_params + params.require(:organization).permit(:name, :description, :picture) + end end end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 58910526..3d549dfa 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -4,47 +4,4 @@ class OrganizationsController < ApplicationController 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 - - 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 diff --git a/app/models/organization.rb b/app/models/organization.rb index 60a83fef..15362d7a 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,5 +1,5 @@ class Organization < ActiveRecord::Base - has_many :conferences, dependent: :destroy + has_many :conferences validates :name, presence: true diff --git a/app/views/admin/organizations/_form.html.haml b/app/views/admin/organizations/_form.html.haml index c41f0cff..c83facbb 100644 --- a/app/views/admin/organizations/_form.html.haml +++ b/app/views/admin/organizations/_form.html.haml @@ -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.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? - if @organization.picture = image_tag(@organization.picture.thumb.url, width: '20%') @@ -10,4 +10,4 @@ - if @organization.new_record? = f.submit 'Create Organization', class: 'btn btn-success' - else - = f.submit 'Update Organization', class: 'btn btn-success' \ No newline at end of file + = f.submit 'Update Organization', class: 'btn btn-success' diff --git a/app/views/admin/organizations/index.html.haml b/app/views/admin/organizations/index.html.haml index 0a751460..f0a8c3c7 100644 --- a/app/views/admin/organizations/index.html.haml +++ b/app/views/admin/organizations/index.html.haml @@ -25,7 +25,7 @@ = organization.conferences.count %td .btn-group - = link_to 'Edit', edit_organization_path(organization), + = link_to 'Edit', edit_admin_organization_path(organization), method: :get, class: 'btn btn-primary' = 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?" } diff --git a/app/views/layouts/_admin_sidebar_index.html.haml b/app/views/layouts/_admin_sidebar_index.html.haml index f1cf8b75..3844339b 100644 --- a/app/views/layouts/_admin_sidebar_index.html.haml +++ b/app/views/layouts/_admin_sidebar_index.html.haml @@ -32,7 +32,8 @@ = link_to(admin_revision_history_path) do %span.fa.fa-history Revision History - %li - = link_to(admin_organizations_path) do - %span.fa.fa-group - Organizations + - if ENV['ORGANIZATIONS_ENABLED'] == 'true' + %li + = link_to(admin_organizations_path) do + %span.fa.fa-group + Organizations diff --git a/app/views/layouts/_user_menu.html.haml b/app/views/layouts/_user_menu.html.haml index 14d32fed..01432b3c 100644 --- a/app/views/layouts/_user_menu.html.haml +++ b/app/views/layouts/_user_menu.html.haml @@ -49,7 +49,8 @@ = link_to(admin_revision_history_path) do %span.fa.fa-history Revision History - %li - = link_to(admin_organizations_path) do - %span.fa.fa-group - Organizations + - if ENV['ORGANIZATIONS_ENABLED'] == 'true' + %li + = link_to(admin_organizations_path) do + %span.fa.fa-group + Organizations diff --git a/app/views/organizations/_form.html.haml b/app/views/organizations/_form.html.haml deleted file mode 100644 index c41f0cff..00000000 --- a/app/views/organizations/_form.html.haml +++ /dev/null @@ -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' \ No newline at end of file diff --git a/app/views/organizations/edit.html.haml b/app/views/organizations/edit.html.haml deleted file mode 100644 index 1f65d485..00000000 --- a/app/views/organizations/edit.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -.container - .row - .col-md-12 - = render 'form' diff --git a/app/views/organizations/index.html.haml b/app/views/organizations/index.html.haml index b87f156b..b2794bd8 100644 --- a/app/views/organizations/index.html.haml +++ b/app/views/organizations/index.html.haml @@ -4,7 +4,7 @@ %h1 Organizations .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| .col-md-4 .thumbnail @@ -13,5 +13,4 @@ %h4 = organization.name %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' diff --git a/app/views/organizations/new.html.haml b/app/views/organizations/new.html.haml deleted file mode 100644 index 1f65d485..00000000 --- a/app/views/organizations/new.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -.container - .row - .col-md-12 - = render 'form'