change routes to use clientid

add json files
add jsonbuilder
This commit is contained in:
Tyrel Souza 2014-04-09 11:06:07 -04:00
parent 3410022799
commit c6d2a47b2a
5 changed files with 33 additions and 8 deletions

View File

@ -20,7 +20,7 @@ gem 'uglifier'
gem 'unicorn' gem 'unicorn'
gem 'foundation-rails' gem 'foundation-rails'
gem 'devise' gem 'devise'
gem 'jbuilder'
group :development do group :development do
gem 'foreman' gem 'foreman'

View File

@ -94,6 +94,9 @@ GEM
high_voltage (2.1.0) high_voltage (2.1.0)
hike (1.2.3) hike (1.2.3)
i18n (0.6.9) i18n (0.6.9)
jbuilder (2.0.6)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (3.1.0) jquery-rails (3.1.0)
railties (>= 3.0, < 5.0) railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
@ -230,6 +233,7 @@ DEPENDENCIES
foreman foreman
foundation-rails foundation-rails
high_voltage high_voltage
jbuilder
jquery-rails jquery-rails
launchy launchy
newrelic_rpm (>= 3.7.3) newrelic_rpm (>= 3.7.3)

View File

@ -13,7 +13,7 @@ class CampaignsController < ApplicationController
# GET /campaigns/new # GET /campaigns/new
def new def new
@campaign = Campaign.new @campaign = Campaign.new
@campaign.videolistings @campaign.videolistings.build
end end
# GET /campaigns/1/edit # GET /campaigns/1/edit
@ -22,9 +22,7 @@ class CampaignsController < ApplicationController
# POST /campaigns # POST /campaigns
def create def create
clientid = campaign_params.delete(:clientid) @campaign = Campaign.new campaign_params
@campaign = Campaign.find_or_create_by(clientid: clientid)
@campaign.update(campaign_params)
if @campaign.save if @campaign.save
respond_to do |format| respond_to do |format|
@ -54,7 +52,7 @@ class CampaignsController < ApplicationController
private private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_campaign def set_campaign
@campaign = Campaign.find(params[:id]) @campaign = Campaign.find_by_clientid(params[:clientid]) || not_found
end end
# Only allow a trusted parameter "white list" through. # Only allow a trusted parameter "white list" through.
@ -67,4 +65,8 @@ class CampaignsController < ApplicationController
:musicselection, :clientprovidedscript, :keywords, :focus, :notes, :asseturls,]) :musicselection, :clientprovidedscript, :keywords, :focus, :notes, :asseturls,])
end end
def not_found
raise ActionController::RoutingError.new("Not Found by clientid")
end
end end

View File

@ -0,0 +1,19 @@
json.campaigns @campaigns do |campaign|
json.clientid campaign.clientid
json.listingcode campaign.listingcode
json.billingcode campaign.billingcode
json.advertisername campaign.advertisername
json.address1 campaign.address1
json.address2 campaign.address2
json.city campaign.city
json.state campaign.state
json.zip campaign.zip
json.emailaddress campaign.emailaddress
json.customerfirstname campaign.customerfirstname
json.customerlastname campaign.customerlastname
json.salesrep campaign.salesrep
json.salesrepemail campaign.salesrepemail
json.businessphone campaign.businessphone
json.contactphone campaign.contactphone
json.websiteurl campaign.websiteurl
end

View File

@ -3,6 +3,6 @@ Vidpush::Application.routes.draw do
devise_for :users devise_for :users
root to: "campaigns#index" root to: "campaigns#index"
resources :campaigns resources :campaigns, param: :clientid
resources :videolistings, param: :videocode
end end