From 7bbb0da17a517e0ec9e049677aad2bd7b48d799d Mon Sep 17 00:00:00 2001 From: Shriyansh Date: Tue, 5 Apr 2016 02:24:14 +0530 Subject: [PATCH] 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'