Skip to content

Instantly share code, notes, and snippets.

@willkessler
Created September 27, 2013 21:59
Show Gist options
  • Save willkessler/6735837 to your computer and use it in GitHub Desktop.
Save willkessler/6735837 to your computer and use it in GitHub Desktop.
class BrandSubscriptionsController < ApplicationController
before_filter :require_login
def new
flash.clear
render :new, :layout => "brands"
end
def create
Rails.logger.info('___ agreed:' + params[:brand_subscription][:agreed_to_terms] + '<<')
if params[:brand_subscription][:agreed_to_terms].to_i < 1
flash[:danger] = 'Please check the terms and conditions checkbox.'
render :action => 'new', :layout => "brands"
else
@brandSubscriptionHash = params[:brand_subscription]
if @brandSubscriptionHash[:product_name].empty? ||
@brandSubscriptionHash[:short_description].empty? ||
@brandSubscriptionHash[:customer_name].empty? ||
@brandSubscriptionHash[:customer_email].empty? ||
@brandSubscriptionHash[:company_name].empty?
flash[:danger] = 'All fields are required.'
render :new, :layout => "brands"
else
@brandSubscription = BrandSubscription.new(@brandSubscriptionHash)
if @brandSubscription.save
flash[:success] = "Your subscription was saved."
else
flash[:danger] = "No fields can be left blank. Please check the terms and conditions checkbox as well."
end
Rails.logger.info('___' + params.inspect)
render :new, :layout => "brands"
end
end
end
end
<div class="container">
<div class="header">
<h3 style="margin-left:-20px;" class="muted">You're 60 Seconds Away from Your Free Trial</h3>
</div>
<div class="row">
<h4>1. Product Information.</h4>
<div class="form-horizontal">
<%= form_for :brand_subscription, url: brand_subscriptions_path do |f| %>
<div class="form-group" style="margin-left:20px;">
<%= f.label :product_name %>
<%= f.text_field :product_name, class: 'form-control', style: 'width:300px', placeholder: "What is your product called?" %>
</div>
<div class="form-group" style="margin-left:20px;">
<%= f.label :short_description %>
<%= f.text_field :short_description, label: "What is it? (2-3 word description)", class: 'form-control', style: 'width:600px;', placeholder: "Please give us a short description of what your product is (2-3 words)" %>
</div>
<h4>2. Contact Information.</h4>
<div class="form-group" style="margin-left:20px;">
<%= f.label :customer_name %>
<%= f.text_field :customer_name, label: "Name", value: 'fullname', class: 'form-control', style: 'width:600px;', placeholder: "Please enter your full name." %>
</div>
<div class="form-group" style="margin-left:20px;">
<%= f.label :customer_email %>
<%= f.text_field :customer_email, label: "Email", value: 'will@getfresh.com', class: 'form-control', style: 'width:600px;', placeholder: "Please enter an email address." %>
</div>
<div class="form-group" style="margin-left:20px;">
<%= f.label :company_name %>
<%= f.text_field :company_name, label: "Company", value: 'compname', class: 'form-control', style: 'width:600px;', placeholder: "Please enter your company's name." %>
</div>
<div class="form-group" style="margin-left:20px;">
<%= f.check_box(:agreed_to_terms) %>
<label for="brand_subscription_agreed_to_terms">By checking this box, you agree to the Terms of Service, Privacy, and Refund policies.</label>
</div>
<div class="pull-right clearfix" style="margin-bottom:50px;">
<%= f.submit "Start My Free Trial", id: "submit_trial_info", class: "btn btn-primary btn-success" %>
</div>
<% end %>
</div>
</div>
</div>
routes:
resources :brand_subscriptions, only: [:new, :create]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment