Skip to content

Instantly share code, notes, and snippets.

@osnysantos
Last active January 25, 2016 10:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save osnysantos/86decf74c02ffe88daa3 to your computer and use it in GitHub Desktop.
def grava_lead(item_usuario, item_id, item_titulo, tipo, nome = nil, email = nil, telefone = nil, empresa = nil, publico = nil, tags = nil, is_downloaded = nil, save_db = true, departamento = nil, nivel_hierarquico = nil)
usuario_id = session[:usuario_id] || cookies["usuario_id"]
Rails.logger.info "usuario_id: #{usuario_id}"
if email
user = Usuario.find_by_email(email)
else
user = Usuario.find(usuario_id) if usuario_id
end
if !usuario_id && user
cookies["usuario_id"] = {:value => user.id.to_s, :expires => 99.month.from_now}
end
if user
user.update_attribute(:tags_compra, tags)
else
user_password = Usuario.random_string(10)
user = Usuario.new(
:email => email,
:senha => user_password,
:pais => "--",
:name => nome
)
user.publico = false if publico == true || publico == "1"
user.company = empresa if empresa
user.save
if user.save
inserir_usuario_sessao(user)
else
user = Usuario.find_by_email(email)
inserir_usuario_sessao(user) if user
end
end
end
...
if grava_lead(
@white_paper.usuario_id,
@white_paper.id,
@white_paper.title,
4,
params[:get_lead][:name],
params[:get_lead][:email],
params[:get_lead][:phone],
params[:get_lead][:company],
nil,
nil,
nil,
)
...
else
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment