From 154f4a400c36ac6eb9d64b3ef846e55811f8c3a4 Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Sun, 3 Apr 2016 19:25:41 +0530 Subject: [PATCH 1/9] venue_commercial association establihed --- .../venue_commercial_controller.rb | 58 +++++++++++++++++++ app/models/venue.rb | 1 + config/routes.rb | 2 + 3 files changed, 61 insertions(+) create mode 100644 app/controllers/venue_commercial_controller.rb diff --git a/app/controllers/venue_commercial_controller.rb b/app/controllers/venue_commercial_controller.rb new file mode 100644 index 00000000..87777f3b --- /dev/null +++ b/app/controllers/venue_commercial_controller.rb @@ -0,0 +1,58 @@ +module Admin + class CommercialsController < Admin::BaseController + load_and_authorize_resource :conference, find_by: :short_title + load_and_authorize_resource :venue ,through: :conference, singelton: true + before_action :set_venue + + def create + @commercial = @venue.commercial.build(commercial_params) + authorize! :create, @commercial + + #FIXME redirect to tab#commercial + if @commercial.save + redirect_to admin_conference_venue_path, + notice: 'Commercial was successfully created.' + else + redirect_to admin_conference_venue_path, + error: 'An error prohibited this Commercial from being saved: '\ + "#{@commercial.errors.full_messages.join('. ')}." + + end + end + + def update + if @commercial.update(commercial_params) + redirect_to admin_conference_venue_path, + notice: 'Commercial was successfully updated.' + else + redirect_to admin_conference_venue_path, + error: 'An error prohibited this Commercial from being saved: '\ + "#{@commercial.errors.full_messages.join('. ')}." + end + end + + def destroy + @commercial.destroy + redirect_to admin_conference_venue_path, notice: 'Commercial was successfully destroyed.' + end + + def render_commercial + result = Commercial.render_from_url(params[:url]) + if result[:error] + render text: result[:error], status: 400 + else + render text: result[:html] + end + end + + private + + def commercial_params + params.require(:commercial).permit(:url) + end + + def set_venue + @venue = @conference.venue + end + end +end diff --git a/app/models/venue.rb b/app/models/venue.rb index 25d3b8cd..914c7c0a 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -1,5 +1,6 @@ class Venue < ActiveRecord::Base belongs_to :conference + has_one :commercial, as: :commercialable, dependent: :destroy has_many :rooms, dependent: :destroy before_create :generate_guid diff --git a/config/routes.rb b/config/routes.rb index 9ec449f9..e0c7150c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,6 +43,8 @@ Osem::Application.routes.draw do # Singletons resource :splashpage resource :venue do + get 'venue_commercial/render_commercial' => 'venue_commercial#render_commercial' + resource :venue_commercial, only: [:create, :update, :destroy] resources :rooms, except: [:show] end resource :registration_period From 6f667a865ba49a896620c41657764c4b83b6987f Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Sun, 3 Apr 2016 22:08:46 +0530 Subject: [PATCH 2/9] create_venue_commercial added --- .../venue_commercials_controller.rb} | 4 +-- app/models/venue.rb | 1 + app/views/admin/venues/_form.html.haml | 27 +++++++++++++++++++ config/routes.rb | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) rename app/controllers/{venue_commercial_controller.rb => admin/venue_commercials_controller.rb} (92%) diff --git a/app/controllers/venue_commercial_controller.rb b/app/controllers/admin/venue_commercials_controller.rb similarity index 92% rename from app/controllers/venue_commercial_controller.rb rename to app/controllers/admin/venue_commercials_controller.rb index 87777f3b..d46b858b 100644 --- a/app/controllers/venue_commercial_controller.rb +++ b/app/controllers/admin/venue_commercials_controller.rb @@ -1,11 +1,11 @@ module Admin - class CommercialsController < Admin::BaseController + class VenueCommercialsController < Admin::BaseController load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :venue ,through: :conference, singelton: true before_action :set_venue def create - @commercial = @venue.commercial.build(commercial_params) + @commercial = @venue.build_commercial(commercial_params) authorize! :create, @commercial #FIXME redirect to tab#commercial diff --git a/app/models/venue.rb b/app/models/venue.rb index 914c7c0a..4642a3ce 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -4,6 +4,7 @@ class Venue < ActiveRecord::Base has_many :rooms, dependent: :destroy before_create :generate_guid + accepts_nested_attributes_for :commercial, allow_destroy: true validates :name, :street, :city, :country, presence: true validates :conference_id, presence: true, uniqueness: true diff --git a/app/views/admin/venues/_form.html.haml b/app/views/admin/venues/_form.html.haml index f63d34cc..639008ea 100644 --- a/app/views/admin/venues/_form.html.haml +++ b/app/views/admin/venues/_form.html.haml @@ -12,3 +12,30 @@ = image_tag @venue.photo(:thumb) = f.input :photo = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } + + .row + .col-md-6 + #resource-content + #resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' } + .row + .col-md-6 + = semantic_form_for(@venue.create_commercial,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' }, + hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.' + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true } + %hr +- @venue.commercial do |commercial| + - if commercial.persisted? + .col-md-4 + .thumbnail + .flexvideo{ id: "resource-content-#{commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: commercial } + .caption + - if can? :update, commercial + = semantic_form_for commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: commercial) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{commercial.id}", required: 'required' }, hint: 'Just paste the url of your video/photo provider' + = f.action :submit, as: :button, button_html: { class: 'btn btn-success' }, label: 'Update' + - if can? :destroy, commercial + = link_to 'Delete', admin_conference_venue_venue_commercial_path(@conference.short_title, commercial.id), + method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' + %hr diff --git a/config/routes.rb b/config/routes.rb index e0c7150c..28b5884f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,7 +43,7 @@ Osem::Application.routes.draw do # Singletons resource :splashpage resource :venue do - get 'venue_commercial/render_commercial' => 'venue_commercial#render_commercial' + get 'venue_commercial/render_commercial' => 'venue_commercials#render_commercial' resource :venue_commercial, only: [:create, :update, :destroy] resources :rooms, except: [:show] end From dc0da8c500637feb2cca68f0609fa4db3363ca3e Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Sun, 3 Apr 2016 22:19:08 +0530 Subject: [PATCH 3/9] defined ,tabular form defined ,tabular form --- .../admin/venue_commercials_controller.rb | 10 +-- app/views/admin/venues/_form.html.haml | 84 +++++++++++-------- 2 files changed, 53 insertions(+), 41 deletions(-) diff --git a/app/controllers/admin/venue_commercials_controller.rb b/app/controllers/admin/venue_commercials_controller.rb index d46b858b..3b8b51e0 100644 --- a/app/controllers/admin/venue_commercials_controller.rb +++ b/app/controllers/admin/venue_commercials_controller.rb @@ -10,10 +10,10 @@ module Admin #FIXME redirect to tab#commercial if @commercial.save - redirect_to admin_conference_venue_path, + redirect_to edit_admin_conference_venue_path, notice: 'Commercial was successfully created.' else - redirect_to admin_conference_venue_path, + redirect_to edit_admin_conference_venue_path, error: 'An error prohibited this Commercial from being saved: '\ "#{@commercial.errors.full_messages.join('. ')}." @@ -22,10 +22,10 @@ module Admin def update if @commercial.update(commercial_params) - redirect_to admin_conference_venue_path, + redirect_to edit_admin_conference_venue_path, notice: 'Commercial was successfully updated.' else - redirect_to admin_conference_venue_path, + redirect_to edit_admin_conference_venue_path, error: 'An error prohibited this Commercial from being saved: '\ "#{@commercial.errors.full_messages.join('. ')}." end @@ -33,7 +33,7 @@ module Admin def destroy @commercial.destroy - redirect_to admin_conference_venue_path, notice: 'Commercial was successfully destroyed.' + redirect_to edit_admin_conference_venue_path, notice: 'Commercial was successfully destroyed.' end def render_commercial diff --git a/app/views/admin/venues/_form.html.haml b/app/views/admin/venues/_form.html.haml index 639008ea..d40779ee 100644 --- a/app/views/admin/venues/_form.html.haml +++ b/app/views/admin/venues/_form.html.haml @@ -2,40 +2,52 @@ .col-md-12 .page-header %h1 Venue -.row - .col-md-8 - = semantic_form_for(@venue, url: admin_conference_venue_path(@conference.short_title)) do |f| - = f.inputs :name, :website - = f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint - = f.inputs :street, :postalcode, :city, :country, :latitude, :longitude - - unless @venue.photo.blank? - = image_tag @venue.photo(:thumb) - = f.input :photo - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } +.tabbable + %ul.nav.nav-tabs + %li.active + = link_to 'Details', '#details-content', 'data-toggle' => 'tab' + %li + = link_to 'Commercials', '#commercials-content', 'data-toggle' => 'tab' + + .tab-content + #details-content.tab-pane.active + .col-md-8 + = semantic_form_for(@venue, url: admin_conference_venue_path(@conference.short_title)) do |f| + = f.inputs :name, :website + = f.input :description, input_html: { rows: 5, cols: 20, data: { provide: 'markdown-editable' } }, hint: markdown_hint + = f.inputs :street, :postalcode, :city, :country, :latitude, :longitude + - unless @venue.photo.blank? + = image_tag @venue.photo(:thumb) + = f.input :photo + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } - .row - .col-md-6 - #resource-content - #resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' } - .row - .col-md-6 - = semantic_form_for(@venue.create_commercial,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f| - = f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' }, - hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.' - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true } - %hr -- @venue.commercial do |commercial| - - if commercial.persisted? - .col-md-4 - .thumbnail - .flexvideo{ id: "resource-content-#{commercial.id}"} - = render partial: 'shared/media_item', locals: { commercial: commercial } - .caption - - if can? :update, commercial - = semantic_form_for commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: commercial) do |f| - = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{commercial.id}", required: 'required' }, hint: 'Just paste the url of your video/photo provider' - = f.action :submit, as: :button, button_html: { class: 'btn btn-success' }, label: 'Update' - - if can? :destroy, commercial - = link_to 'Delete', admin_conference_venue_venue_commercial_path(@conference.short_title, commercial.id), - method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' - %hr + #commercials-content.tab-pane + - if @venue + .row + .col-md-6 + #resource-content + #resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' } + .row + .col-md-6 + = semantic_form_for(@venue.create_commercial,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' }, + hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.' + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true } + %hr + - @venue.commercial do |commercial| + - if commercial.persisted? + .col-md-4 + .thumbnail + .flexvideo{ id: "resource-content-#{commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: commercial } + .caption + - if can? :update, commercial + = semantic_form_for commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: commercial.id) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{commercial.id}", required: 'required' }, hint: 'Just paste the url of your video/photo provider' + = f.action :submit, as: :button, button_html: { class: 'btn btn-success' }, label: 'Update' + - if can? :destroy, commercial + = link_to 'Delete', admin_conference_venue_venue_commercial_path(@conference.short_title, commercial.id), + method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' + %hr + - else + hint: 'First Create Venue, then update commercial' From 7bbb0da17a517e0ec9e049677aad2bd7b48d799d Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Tue, 5 Apr 2016 02:24:14 +0530 Subject: [PATCH 4/9] done with creating relationship and generating view for venue_commercials --- .../admin/venue_commercials_controller.rb | 5 ++ app/views/admin/venues/_form.html.haml | 46 ++++++++++--------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/controllers/admin/venue_commercials_controller.rb b/app/controllers/admin/venue_commercials_controller.rb index 3b8b51e0..0e0a4b28 100644 --- a/app/controllers/admin/venue_commercials_controller.rb +++ b/app/controllers/admin/venue_commercials_controller.rb @@ -3,6 +3,7 @@ module Admin load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :venue ,through: :conference, singelton: true before_action :set_venue + before_action :set_commercial , only: [:update , :destroy] def create @commercial = @venue.build_commercial(commercial_params) @@ -54,5 +55,9 @@ module Admin def set_venue @venue = @conference.venue end + + def set_commercial + @commercial = Commercial.find params[:id] + end end end diff --git a/app/views/admin/venues/_form.html.haml b/app/views/admin/venues/_form.html.haml index d40779ee..7460223c 100644 --- a/app/views/admin/venues/_form.html.haml +++ b/app/views/admin/venues/_form.html.haml @@ -22,32 +22,34 @@ = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } #commercials-content.tab-pane - - if @venue - .row - .col-md-6 - #resource-content - #resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' } - .row - .col-md-6 - = semantic_form_for(@venue.create_commercial,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f| - = f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' }, - hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.' - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true } - %hr - - @venue.commercial do |commercial| - - if commercial.persisted? + - if can? :create, @venue.commercial + - if @venue.commercial + - if @venue.commercial.persisted? .col-md-4 .thumbnail - .flexvideo{ id: "resource-content-#{commercial.id}"} - = render partial: 'shared/media_item', locals: { commercial: commercial } + .flexvideo{ id: "resource-content-#{@venue.commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: @venue.commercial } .caption - - if can? :update, commercial - = semantic_form_for commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: commercial.id) do |f| - = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{commercial.id}", required: 'required' }, hint: 'Just paste the url of your video/photo provider' + - if can? :update, @venue.commercial + = semantic_form_for @venue.commercial, as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: @venue.commercial.id) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { id: "commercial_url_#{@venue.commercial.id}", required: 'required' }, hint: 'Just paste the url of your video/photo provider' = f.action :submit, as: :button, button_html: { class: 'btn btn-success' }, label: 'Update' - - if can? :destroy, commercial - = link_to 'Delete', admin_conference_venue_venue_commercial_path(@conference.short_title, commercial.id), + - if can? :destroy, @venue.commercial + = link_to 'Delete', admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: @venue.commercial.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' - %hr + %hr + - else + .row + .col-md-6 + #resource-content + #resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' } + .row + .col-md-6 + = semantic_form_for(Commercial.new,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' }, + hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.' + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true } + %hr + - else hint: 'First Create Venue, then update commercial' From 5186dfcb1204d7b330a5b4b722a0ed8b59c95944 Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Tue, 5 Apr 2016 03:07:07 +0530 Subject: [PATCH 5/9] secured Ux --- app/views/admin/venues/_form.html.haml | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/views/admin/venues/_form.html.haml b/app/views/admin/venues/_form.html.haml index 7460223c..00f3e501 100644 --- a/app/views/admin/venues/_form.html.haml +++ b/app/views/admin/venues/_form.html.haml @@ -22,8 +22,21 @@ = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } #commercials-content.tab-pane - - if can? :create, @venue.commercial - - if @venue.commercial + - if can? :create, @venue.commercial and @venue.id + - if @venue.commercial.nil? + .row + .col-md-6 + #resource-content + #resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' } + + .row + .col-md-6 + = semantic_form_for(Commercial.new,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f| + = f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' }, + hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.' + = f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true } + %hr + - else - if @venue.commercial.persisted? .col-md-4 .thumbnail @@ -38,18 +51,6 @@ = link_to 'Delete', admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title, id: @venue.commercial.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %hr - - else - .row - .col-md-6 - #resource-content - #resource-placeholder{ style: 'background-color:#d3d3d3; float: left; width: 400px; height: 250px; margin: 5px; border-width: 1px; border-style: solid; border-color: rgba(0,0,0,.2);' } - .row - .col-md-6 - = semantic_form_for(Commercial.new,as: :commercial, url: admin_conference_venue_venue_commercial_path(conference_id: @conference.short_title)) do |f| - = f.input :url, label: 'URL', as: :string, input_html: { required: 'required', type: 'url' }, - hint: 'Just paste the url of your video/photo provider. Currently supported: YouTube, Vimeo, SpeakerDeck, SlideShare, Instagram, Flickr.' - = f.action :submit, as: :button, button_html: { class: 'btn btn-primary pull-right', disabled: true } - %hr - else - hint: 'First Create Venue, then update commercial' + First Create Venue, then update commercial From 5cdedbf9a6f818b5a142a0f89a523bf9ce17af57 Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Wed, 6 Apr 2016 20:13:01 +0530 Subject: [PATCH 6/9] rubocop issues solved --- app/controllers/admin/venue_commercials_controller.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/venue_commercials_controller.rb b/app/controllers/admin/venue_commercials_controller.rb index 0e0a4b28..e42f72b1 100644 --- a/app/controllers/admin/venue_commercials_controller.rb +++ b/app/controllers/admin/venue_commercials_controller.rb @@ -1,15 +1,14 @@ module Admin class VenueCommercialsController < Admin::BaseController load_and_authorize_resource :conference, find_by: :short_title - load_and_authorize_resource :venue ,through: :conference, singelton: true + load_and_authorize_resource :venue, through: :conference, singelton: true before_action :set_venue - before_action :set_commercial , only: [:update , :destroy] + before_action :set_commercial, only: [:update, :destroy] def create @commercial = @venue.build_commercial(commercial_params) authorize! :create, @commercial - #FIXME redirect to tab#commercial if @commercial.save redirect_to edit_admin_conference_venue_path, notice: 'Commercial was successfully created.' @@ -51,11 +50,11 @@ module Admin def commercial_params params.require(:commercial).permit(:url) end - + def set_venue @venue = @conference.venue end - + def set_commercial @commercial = Commercial.find params[:id] end From 3bcdbe7469572558df0584a5e07999dc50553bfd Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Sat, 9 Apr 2016 02:00:32 +0530 Subject: [PATCH 7/9] defined ability for user with roles -organizer and cfp's, and some improvements in controller --- .../admin/venue_commercials_controller.rb | 13 ++----------- app/models/ability.rb | 3 +++ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/venue_commercials_controller.rb b/app/controllers/admin/venue_commercials_controller.rb index e42f72b1..3ee1b36e 100644 --- a/app/controllers/admin/venue_commercials_controller.rb +++ b/app/controllers/admin/venue_commercials_controller.rb @@ -1,9 +1,8 @@ module Admin class VenueCommercialsController < Admin::BaseController load_and_authorize_resource :conference, find_by: :short_title - load_and_authorize_resource :venue, through: :conference, singelton: true - before_action :set_venue - before_action :set_commercial, only: [:update, :destroy] + load_and_authorize_resource :venue, through: :conference, singleton: true + load_and_authorize_resource :commercial, through: :venue, singleton: true def create @commercial = @venue.build_commercial(commercial_params) @@ -50,13 +49,5 @@ module Admin def commercial_params params.require(:commercial).permit(:url) end - - def set_venue - @venue = @conference.venue - end - - def set_commercial - @commercial = Commercial.find params[:id] - end end end diff --git a/app/models/ability.rb b/app/models/ability.rb index ef569ec7..7f9f195d 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -153,6 +153,8 @@ class Ability can :manage, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id) can :manage, Venue, conference_id: conf_ids_for_organizer + can :manage, Commercial, commercialable_type: 'Venue', + commercialable_id: Venue.where(conference_id: conf_ids_for_organizer).pluck(:id) can :manage, Lodging, conference_id: conf_ids_for_organizer can :manage, Room, venue: { conference_id: conf_ids_for_organizer} can :manage, Sponsor, conference_id: conf_ids_for_organizer @@ -188,6 +190,7 @@ class Ability can :manage, EmailSettings, conference_id: conf_ids_for_cfp can :manage, Room, venue: { conference_id: conf_ids_for_cfp } can :show, Venue, conference_id: conf_ids_for_cfp + can :show, Commercial, commercialable_type: 'Venue', commercialable_id: Venue.where(conference_id: conf_ids_for_cfp).pluck(:id) can :manage, Cfp, program: { conference_id: conf_ids_for_cfp } can :manage, Program, conference_id: conf_ids_for_cfp can :manage, Commercial, commercialable_type: 'Event', From 0ca19ea67a43bc12c5ae6bd67dda70479f4bd17d Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Sat, 9 Apr 2016 02:52:06 +0530 Subject: [PATCH 8/9] added views for public view on splashpage,venue_edit,venue --- .../admin/venue_commercials_controller.rb | 10 +++++----- app/views/admin/venues/show.html.haml | 14 ++++++++++---- app/views/conference/_venue.html.haml | 13 +++++++++++-- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/venue_commercials_controller.rb b/app/controllers/admin/venue_commercials_controller.rb index 3ee1b36e..20117e15 100644 --- a/app/controllers/admin/venue_commercials_controller.rb +++ b/app/controllers/admin/venue_commercials_controller.rb @@ -9,10 +9,10 @@ module Admin authorize! :create, @commercial if @commercial.save - redirect_to edit_admin_conference_venue_path, + redirect_to admin_conference_venue_path, notice: 'Commercial was successfully created.' else - redirect_to edit_admin_conference_venue_path, + redirect_to admin_conference_venue_path, error: 'An error prohibited this Commercial from being saved: '\ "#{@commercial.errors.full_messages.join('. ')}." @@ -21,10 +21,10 @@ module Admin def update if @commercial.update(commercial_params) - redirect_to edit_admin_conference_venue_path, + redirect_to admin_conference_venue_path, notice: 'Commercial was successfully updated.' else - redirect_to edit_admin_conference_venue_path, + redirect_to admin_conference_venue_path, error: 'An error prohibited this Commercial from being saved: '\ "#{@commercial.errors.full_messages.join('. ')}." end @@ -32,7 +32,7 @@ module Admin def destroy @commercial.destroy - redirect_to edit_admin_conference_venue_path, notice: 'Commercial was successfully destroyed.' + redirect_to admin_conference_venue_path, notice: 'Commercial was successfully destroyed.' end def render_commercial diff --git a/app/views/admin/venues/show.html.haml b/app/views/admin/venues/show.html.haml index 18266ede..48fe9bcd 100644 --- a/app/views/admin/venues/show.html.haml +++ b/app/views/admin/venues/show.html.haml @@ -9,10 +9,16 @@ .col-md-6 - if @conference.venue.location? = render 'conference/venue_map' - - elsif @conference.venue.photo.blank? - %img{ "data-src" => "holder.js/300x200?text=No Image Set", class: 'img-responsive img-rounded' } - - elsif !@conference.venue.photo.blank? - =image_tag(@conference.venue.photo, class: 'img-responsive img-rounded') + -else + - if @venue.commercial.nil? + .row + %img{ "data-src" => "holder.js/500x300?text=No Commercial Set", class: 'img-responsive img-rounded' } + - else + - if @venue.commercial.persisted? + .thumbnail + .flexvideo{ id: "resource-content-#{@venue.commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: @venue.commercial } + .col-md-6 %address %strong diff --git a/app/views/conference/_venue.html.haml b/app/views/conference/_venue.html.haml index b2b7874b..c0650ca3 100644 --- a/app/views/conference/_venue.html.haml +++ b/app/views/conference/_venue.html.haml @@ -6,12 +6,21 @@ -else .container .row - .col-md-12 + - if @conference.venue.commercial.nil? + .col-md-6 + %img{ "data-src" => "holder.js/500x300?text=No Commercial Set", class: 'img-responsive img-rounded' } + + -else @conference.venue.commercial.persisted? + .col-md-5 + .thumbnail + .flexvideo{ id: "resource-content-#{@conference.venue.commercial.id}"} + = render partial: 'shared/media_item', locals: { commercial: @conference.venue.commercial } + + .col-md-6 %h2.text-center = "#{@conference.venue.city} / #{@conference.venue.country_name}" .col-md-6 .thumbnail - =image_tag(@conference.venue.photo, class: 'img-responsive img-rounded') unless @conference.venue.photo.blank? .caption - unless @conference.venue.description.blank? = markdown(@conference.venue.description) From f6b5cb03e86b6b79b64ffad9c23a48614830b88d Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Thu, 21 Apr 2016 20:21:23 +0530 Subject: [PATCH 9/9] redesigned view of splashpage --- app/views/conference/_venue.html.haml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/views/conference/_venue.html.haml b/app/views/conference/_venue.html.haml index c0650ca3..74dad5a7 100644 --- a/app/views/conference/_venue.html.haml +++ b/app/views/conference/_venue.html.haml @@ -6,11 +6,7 @@ -else .container .row - - if @conference.venue.commercial.nil? - .col-md-6 - %img{ "data-src" => "holder.js/500x300?text=No Commercial Set", class: 'img-responsive img-rounded' } - - -else @conference.venue.commercial.persisted? + - if @conference.venue.commercial.present? and @conference.venue.commercial.persisted? .col-md-5 .thumbnail .flexvideo{ id: "resource-content-#{@conference.venue.commercial.id}"}