diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 695fcda..006244d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,8 +2,8 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :null_session - before_action :authenticate_user_from_token! - before_action :authenticate_user! #unless Rails.env.test? + before_action :authenticate_user_from_token!, except: [:publish] + before_action :authenticate_user!, except: [:publish] #unless Rails.env.test? private diff --git a/app/controllers/videolistings_controller.rb b/app/controllers/videolistings_controller.rb index c841e75..ee3f7ed 100644 --- a/app/controllers/videolistings_controller.rb +++ b/app/controllers/videolistings_controller.rb @@ -1,54 +1,28 @@ class VideolistingsController < ApplicationController - before_action :set_videolisting, only: [:show, :edit, :update, :destroy] + before_action :set_videolisting, only: [:publish] - # GET /videolistings - def index - @videolistings = Videolisting.all - end - - # GET /videolistings/1 - def show - end - - # GET /videolistings/new - def new - @videolisting = Videolisting.new - end - - # GET /videolistings/1/edit - def edit - end - - # POST /videolistings - def create - @videolisting = Videolisting.new(videolisting_params) - - if @videolisting.save - redirect_to @videolisting, notice: 'Videolisting was successfully created.' + def publish + if @videolisting.published? + @message = "Campaign Already Published." + elsif @videolisting.campaign.processed? + @videolisting.published = true + @videolisting.save + #TODO: SEND OUT EMAIL HERE. + @message = "Campaign Published Successfully." else - render action: 'new' + @message = "Error: Campaign Not Published." end end - # PATCH/PUT /videolistings/1 - def update - if @videolisting.update(videolisting_params) - redirect_to @videolisting, notice: 'Videolisting was successfully updated.' - else - render action: 'edit' - end - end - - # DELETE /videolistings/1 - def destroy - @videolisting.destroy - redirect_to videolistings_url, notice: 'Videolisting was successfully destroyed.' - end - private # Use callbacks to share common setup or constraints between actions. def set_videolisting - @videolisting = Videolisting.find(params[:id]) + videocode = params[:videocode] + if params[:videolisting] + @videolisting = Videolisting.find_by_videocode(params[:videolisting][:videocode]) || not_found + else + @videolisting = Videolisting.find_by_videocode(videocode) || not_found + end end # Only allow a trusted parameter "white list" through. diff --git a/app/views/videolistings/_form.html.erb b/app/views/videolistings/_form.html.erb deleted file mode 100644 index 54860d6..0000000 --- a/app/views/videolistings/_form.html.erb +++ /dev/null @@ -1,57 +0,0 @@ -<%= form_for(@videolisting) do |f| %> - <% if @videolisting.errors.any? %> -
Videocode | -Producttypeid | -Remoteassetsarchive | -Voiceoverselection | -Musicselection | -Clientprovidedscript | -Keywords | -Focus | -Notes | -Asseturls | -- | - | - |
---|---|---|---|---|---|---|---|---|---|---|---|---|
<%= videolisting.videocode %> | -<%= videolisting.producttypeid %> | -<%= videolisting.remoteassetsarchive %> | -<%= videolisting.voiceoverselection %> | -<%= videolisting.musicselection %> | -<%= videolisting.clientprovidedscript %> | -<%= videolisting.keywords %> | -<%= videolisting.focus %> | -<%= videolisting.notes %> | -<%= videolisting.asseturls %> | -<%= link_to 'Show', videolisting %> | -<%= link_to 'Edit', edit_videolisting_path(videolisting) %> | -<%= link_to 'Destroy', videolisting, method: :delete, data: { confirm: 'Are you sure?' } %> | -
<%= notice %>
- -- Videocode: - <%= @videolisting.videocode %> -
- -- Producttypeid: - <%= @videolisting.producttypeid %> -
- -- Remoteassetsarchive: - <%= @videolisting.remoteassetsarchive %> -
- -- Voiceoverselection: - <%= @videolisting.voiceoverselection %> -
- -- Musicselection: - <%= @videolisting.musicselection %> -
- -- Clientprovidedscript: - <%= @videolisting.clientprovidedscript %> -
- -- Keywords: - <%= @videolisting.keywords %> -
- -- Focus: - <%= @videolisting.focus %> -
- -- Notes: - <%= @videolisting.notes %> -
- -- Asseturls: - <%= @videolisting.asseturls %> -
- -<%= link_to 'Edit', edit_videolisting_path(@videolisting) %> | -<%= link_to 'Back', videolistings_path %> diff --git a/config/routes.rb b/config/routes.rb index 7daed3d..69dcc55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,12 +4,15 @@ Vidpush::Application.routes.draw do devise_for :users, :controllers => {registrations: "registrations"} else devise_for :users - end root to: "campaigns#index" resources :campaigns, param: :listingcode do - resources :videolistings, param: :videocode + resources :videolistings, param: :videocode do + member do + get 'publish',:defaults => { :format => 'json' } + end + end end end diff --git a/db/migrate/20140424185113_add_published_to_videolisting.rb b/db/migrate/20140424185113_add_published_to_videolisting.rb new file mode 100644 index 0000000..d70cbe0 --- /dev/null +++ b/db/migrate/20140424185113_add_published_to_videolisting.rb @@ -0,0 +1,5 @@ +class AddPublishedToVideolisting < ActiveRecord::Migration + def change + add_column :videolistings, :published, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 03a355b..5724311 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140423215738) do +ActiveRecord::Schema.define(version: 20140424185113) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -112,6 +112,7 @@ ActiveRecord::Schema.define(version: 20140423215738) do t.datetime "updated_at" t.integer "campaign_id" t.string "toneofvideo" + t.boolean "published" end end