Last active
December 12, 2015 00:49
-
-
Save patrickcurl/4686669 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for(lead) do |f| %> | |
<%= f.label :email %> | |
<%= f.text_field :email %> | |
<%= f.fields_for :referral do |builder| %> | |
<%= builder.hidden_field :user_id, :value => "2" %> | |
<% end %> | |
<%= f.submit %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Lead < ActiveRecord::Base | |
attr_accessible :first_name, :last_name, :email, :phone, :address, :city, :state, :zipcode, :referral_attributes | |
has_one :referral | |
has_one :user, :through => :referral | |
delegate :name, :first_name, :last_name, :email, :phone, :address, :city, :state, :zip, :to => :user, :prefix =>true | |
# self.per_page = 5 | |
validates_presence_of :email | |
validates_uniqueness_of :email | |
accepts_nested_attributes_for :referral | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def new | |
#@lead = Lead.new | |
#@user = @ | |
@user = User.find_by_slug(request.subdomain) | |
# @name1 = user.name | |
@lead = Lead.new | |
@lead.build_referral | |
if !user_signed_in? | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @lead } | |
end | |
end | |
if user_signed_in? | |
redirect_to "/webinar" | |
end | |
end | |
def create | |
email = params[:lead][:email] | |
@lead = Lead.find_by_email(email) | |
if @lead | |
session[:user_id] = @lead.id | |
session[:login_type] = "lead" | |
redirect_to root_url, notice: 'logged in' | |
else | |
@lead = Lead.create(params[:lead]) | |
# @lead = @lead.build_referral(user_id: 2) | |
@lead.save | |
respond_to do |format| | |
if @lead.save | |
format.html { redirect_to @lead, notice: 'User was successfully created.' } | |
format.json { render json: @lead, status: :created, location: @lead } | |
else | |
format.html { render "new" } | |
format.json { render json: @lead.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment