-
-
Save doncruse/137294 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
=begin | |
The form/controller works fine in development, and doesn't in production. | |
It DID work fine in production earlier this week, but now it doesn't, | |
and I didn't make any changes to the code. Any ideas, please send to | |
garyz@easysoftsolutions.com. | |
Controller | |
=end | |
class JobseekerprofilesController < ApplicationController | |
include ActsAsTinyURL | |
before_filter :login_required, :except => [:show] | |
caches_page :show | |
def edit | |
@jobseekerprofile = Jobseekerprofile.find_by_user_id(current_user) | |
if @jobseekerprofile.nil? | |
redirect_to new_jobseekerprofile_url | |
return | |
end | |
load_codes | |
end | |
def new | |
@jobseekerprofile = Jobseekerprofile.new | |
@jobseekerprofile.twitter_url = "http://" + (current_user.twittername.nil? ? "" : current_user.twittername) | |
load_codes | |
end | |
def show | |
@jobseekerprofile = Jobseekerprofile.find_by_id(params[:id]) | |
if !@jobseekerprofile || @jobseekerprofile.user.state != 'active' || !@jobseekerprofile.showtopublic | |
@jobseekerprofile = nil | |
else | |
if params[:user_id].nil? || params[:user_id] != @jobseekerprofile.user_id | |
#need to increment the clickthrough counter | |
@jobseekerprofile.update_attribute(:clickthroughs, @jobseekerprofile.clickthroughs + 1) | |
end | |
end | |
end | |
def create | |
@jobseekerprofile = Jobseekerprofile.new(params[:jobseekerprofile]) | |
@jobseekerprofile.user = current_user | |
if !@jobseekerprofile.save | |
flash[:error] = "Please check for errors." | |
load_codes | |
render :action => 'new' | |
else | |
#go to the resume screen | |
redirect_to new_resume_url | |
end | |
end | |
def index | |
@jobseekerprofiles = Jobseekerprofile.find(:all, :order => "updated_at DESC", :conditions => {:showtopublic => true}).paginate(:page => params[:page]) | |
end | |
def update | |
@jobseekerprofile = Jobseekerprofile.find_by_user_id(current_user) | |
@jobseekerprofile.update_attributes(params[:jobseekerprofile]) | |
if !@jobseekerprofile.save | |
load_codes | |
render :action => 'edit' | |
return | |
else | |
flash[:notice] = "Job Seeker profile updated" | |
redirect_to(:action => "edit") | |
end | |
end | |
def tweet | |
@jobseekerprofile = Jobseekerprofile.find_by_user_id(current_user) | |
if @jobseekerprofile.nil? | |
redirect_to(:action => "index") | |
end | |
end | |
def tweetsend | |
@jobseekerprofile = Jobseekerprofile.find_by_user_id(current_user) | |
t = Twitter.new TWEETMYRESUME_LOGIN, TWEETMYRESUME_PASSWORD | |
#make the tinyurl point back to this site, for redirection. Only get it if it hasn't been gotten before (retweet) | |
if @jobseekerprofile.tinyurl_link.empty? | |
tinyurl = tiny_url(Conf.site_url + '/jobseekerprofiles/' + @jobseekerprofile.id.to_s) | |
if tinyurl.code != "200" | |
flash[:error] = "I'm sorry, but there was an error setting up the resume for Twitter. Please try again." | |
render :action => 'tweet' | |
return | |
end | |
@jobseekerprofile.tinyurl_link = tinyurl.body | |
else | |
#need to delete the old tweet | |
if !@jobseekerprofile.tweetid.blank? | |
xmlres = t.destroy_post(@jobseekerprofile.tweetid, "xml") | |
if xmlres.code != "200" && xmlres.code != "404" | |
flash[:error] = "Twitter.com Error : " + xmlres.code + ' - ' + xmlres.body | |
render :action => 'tweet' | |
return | |
end | |
end | |
end | |
# send to twitter | |
if ENV['RAILS_ENV'] == 'production' | |
twitterupdate = @jobseekerprofile.make_twitterupdate | |
xmlres = t.update_status(twitterupdate, "xml") | |
# need to check for errors | |
if xmlres.code != "200" | |
flash[:error] = "There was a problem sending the resume to Twitter. Please try again. If it persists, contact us and give us some detail of what Job Channel you were posting to as well as the following information: Error " + xmlres.code + ' - ' + xmlres.body | |
flash[:error] = TWEETMYRESUME_LOGIN + TWEETMYRESUME_PASSWORD | |
redirect_to tweet_jobseekerprofile_path | |
return | |
end | |
@doc = REXML::Document.new(xmlres.body).root | |
@jobseekerprofile.tweetid = @doc.elements['/status/id'].text | |
else | |
@jobseekerprofile.tweetid = 'developmenttweet' | |
end | |
@jobseekerprofile.lasttweet_at = Time.now | |
if @jobseekerprofile.save | |
UserMailer.deliver_message_to_person(current_user.email, "Your resume has been tweeted from TweetMyJOBS.com", @jobseekerprofile.firstname + ' ' + @jobseekerprofile.lastname + ", you have successfully tweeted your resume to Twitter. The resume has been posted at our Twitter Resume Channel at http://www.twitter.com/tweetmyresume/status/" + @jobseekerprofile.tweetid + "\n\nQuestions? Email us directly by visiting http://www.tweetmyjobs.com/contact.\n\nAdd admin@tweetmyjobs.com to your address book to ensure delivery of TweetMyJOBS.com emails.\n\nSincerely,\n\nThe TweetMyJOBS Team\nTwitter @tweet_my_jobs") | |
flash[:notice] = 'Resume was successfully tweeted to Twitter.' | |
else | |
if !@jobseekerprofile.tweetid.empty? | |
xmlres = t.destroy_post(@jobseekerprofile.tweetid, "xml") | |
end | |
render :action => 'tweet' | |
return | |
end | |
redirect_to tweet_jobseekerprofile_path | |
end | |
def tweetremove | |
@jobseekerprofile = Jobseekerprofile.find_by_user_id(current_user) | |
t = Twitter.new TWEETMYRESUME_LOGIN, TWEETMYRESUME_PASSWORD | |
#need to delete the old tweet | |
if !@jobseekerprofile.tweetid.empty? | |
xmlres = t.destroy_post(@jobseekerprofile.tweetid, "xml") | |
if xmlres.code != "200" && xmlres.code != "404" | |
flash[:error] = "Twitter.com Error : " + xmlres.code + ' - ' + xmlres.body | |
render :action => 'tweet' | |
return | |
end | |
end | |
@jobseekerprofile.tweetid = nil | |
if @jobseekerprofile.save | |
flash[:notice] = 'Resume was successfully removed from Twitter.' | |
else | |
render :action => 'tweet' | |
return | |
end | |
redirect_to tweet_jobseekerprofile_path | |
end | |
def load_codes | |
@jobtypes = Jobtype.find(:all, :order => 'name') | |
@locations = Location.find(:all, :order => 'name') | |
@hourlyranges = Hourlyrange.find(:all) | |
@salaryranges = Salaryrange.find(:all) | |
@careerlevels = Careerlevel.find(:all) | |
@travelpreferences = Travelpreference.find(:all) | |
@visastatuses = Visastatus.find(:all) | |
@positiontypes = Positiontype.find(:all) | |
@countries = Country.find(:all, :order => 'name') | |
end | |
end | |
=begin | |
FORM | |
=end | |
<%if logged_in?%> | |
<h2>Create a Job Seeker profile</h2> | |
<p>Since we do not have a job seeker profile for you yet, please take a few minutes to enter the following information. You can always change it later.</p> | |
<% form_for @jobseekerprofile, :html => { :class => 'MainForm' } do |f| -%> | |
<%= error_messages_for :jobseekerprofile %> | |
<p> | |
<%= label_tag 'firstname', 'First Name' %> | |
<%= f.text_field :firstname, :id => 'firstname', :size => 60 %> | |
<%= label_tag 'lastname', 'Last Name' %> | |
<%= f.text_field :lastname, :id => 'lastname', :size => 60 %> | |
<%= label_tag 'addr1', 'Address Line 1' %> | |
<%= f.text_field :addr1, :id => 'addr1', :size => 60 %> | |
<%= label_tag 'addr2', 'Address Line 2' %> | |
<%= f.text_field :addr2, :id => 'addr2', :size => 60 %> | |
<%= label_tag 'city', 'City' %> | |
<%= f.text_field :city, :id => 'city' %> | |
<%= label_tag 'state', 'State' %> | |
<%= f.select :state, ['AK', | |
'AL', | |
'AR', | |
'AZ', | |
'CA', | |
'CO', | |
'CT', | |
'DC', | |
'DE', | |
'FL', | |
'GA', | |
'HI', | |
'IA', | |
'ID', | |
'IL', | |
'IN', | |
'KS', | |
'KY', | |
'LA', | |
'MA', | |
'MD', | |
'ME', | |
'MI', | |
'MN', | |
'MO', | |
'MS', | |
'MT', | |
'NC', | |
'ND', | |
'NE', | |
'NH', | |
'NJ', | |
'NM', | |
'NV', | |
'NY', | |
'OH', | |
'OK', | |
'OR', | |
'PA', | |
'RI', | |
'SC', | |
'SD', | |
'TN', | |
'TX', | |
'UT', | |
'VA', | |
'VT', | |
'WA', | |
'WI', | |
'WV', | |
'WY'], | |
:include_blank => true %> | |
<%= label_tag 'zip', 'Zip' %> | |
<%= f.text_field :zip, :id => 'zip' %> | |
<%= label_tag "country", "Country" %> | |
<%= f.collection_select :country_id, @countries, :id, :name, :include_blank => true %> | |
<%= label_tag 'homephone', 'Home Phone' %> | |
<%= f.text_field :homephone, :id => 'homephone' %> | |
<%= label_tag 'cellphone', 'Cell Phone' %> | |
<%= f.text_field :cellphone, :id => 'cellphone' %> | |
<%= label_tag 'email', 'Personal Email' %> | |
<%= f.text_field :email, :id => 'email', :size => 60 %> | |
<%= label_tag 'personal_url', 'My Website' %> | |
<%= f.text_field :personal_url, :id => 'personal_url', :size => 60 %> | |
<%= label_tag 'blog_url', 'My Blog' %> | |
<%= f.text_field :blog_url, :id => 'blog_url', :size => 60 %> | |
<%= label_tag 'linkedin_url', 'LinkedIn' %> | |
<%= f.text_field :linkedin_url, :id => 'linkedin_url', :size => 60 %> | |
<%= label_tag 'twitter_url', 'Twitter' %> | |
<%= f.text_field :twitter_url, :id => 'twitter_url', :size => 60 %> | |
<%= label_tag 'facebook_url', 'Facebook' %> | |
<%= f.text_field :facebook_url, :id => 'facebook_url', :size => 60 %> | |
<%= label_tag 'myspace_url', 'MySpace' %> | |
<%= f.text_field :myspace_url, :id => 'myspace_url', :size => 60 %> | |
<%= label_tag 'video_url', "YouTube or other provider's embed code" %> | |
<%= f.text_field :video_url, :id => 'video_url', :size => 60 %> | |
<%= label_tag 'meeboname', 'Meebo' %> | |
<%= f.text_field :meeboname, :id => 'meeboname' %> | |
<%= label_tag 'skypename', 'Skype' %> | |
<%= f.text_field :skypename, :id => 'skypename' %> | |
<%= label_tag "title", "Title (45 characters or less) - this will be in your tweet to Twitter" %> | |
<%= f.text_field :title, :id => 'title', :size => 75 %> | |
<%= label_tag "objectives", "Objectives" %> | |
<%= f.text_area :objectives, :rows => 10%> | |
<%= label_tag "hourlyrange", "Hourly Range" %> | |
<%= f.collection_select :hourlyrange_id, @hourlyranges, :id, :name, {}, {:selected => 1} %> | |
<%= label_tag "salaryrange", "Salary Range" %> | |
<%= f.collection_select :salaryrange_id, @salaryranges, :id, :name, {}, {:selected => 1} %> | |
<%= label_tag "yearsofexp", "Years of Experience" %> | |
<%= f.select :yearsofexp, 0..80, :include_blank => true %> | |
<%= label_tag "careerlevel", "Career Level" %> | |
<%= f.collection_select :careerlevel_id, @careerlevels, :id, :name, {}, {:selected => 1} %> | |
<%= label_tag "travelpreference", "Travel Preference" %> | |
<%= f.collection_select :travelpreference_id, @travelpreferences, :id, :name, {}, {:selected => 1} %> | |
<%= label_tag "visastatus", "Visa Status" %> | |
<%= f.collection_select :visastatus_id, @visastatuses, :id, :name, {}, {:selected => 1} %> | |
<%= label_tag "positiontype", "Employment Type" %> | |
<%= f.collection_select :positiontype_id, @positiontypes, :id, :name, {}, {:selected => 1} %> | |
<%= label_tag "location", "Desired Location" %> | |
<%= f.collection_select :location_id, @locations, :id, :name, :include_blank => true %> | |
<%= label_tag "willrelocate", "Open to Relocation?" %> | |
<%= f.select :willrelocate, [["Yes",true],["No",false]] %> | |
<%= label_tag "jobtype", "Industry" %> | |
<%= f.collection_select :jobtype_id, @jobtypes, :id, :name, :include_blank => true %> | |
<%= label_tag "resumetext", "Resume Text (HTML OK)" %> | |
<%= f.text_area :resumetext, :size => "50x50"%> | |
<p><%= f.submit 'Next', {:class => 'button'} %></p> | |
</p> | |
<% end -%> | |
<%end%> | |
<% content_for(:sidebar) do %> | |
<% end -%> | |
<% content_for(:head) do %> | |
<script type="text/javascript" language="javascript" defer > | |
if(login = document.getElementById('firstname')) | |
{login.focus() | |
} | |
</script> | |
<% end -%> | |
=begin | |
Here's the routes: | |
=end | |
jobseekerprofiles GET /jobseekerprofiles {:controller=>"jobseekerprofiles", :action=>"index"} | |
formatted_jobseekerprofiles GET /jobseekerprofiles.:format {:controller=>"jobseekerprofiles", :action=>"index"} | |
POST /jobseekerprofiles {:controller=>"jobseekerprofiles", :action=>"create"} | |
POST /jobseekerprofiles.:format {:controller=>"jobseekerprofiles", :action=>"create"} | |
new_jobseekerprofile GET /jobseekerprofiles/new {:controller=>"jobseekerprofiles", :action=>"new"} | |
formatted_new_jobseekerprofile GET /jobseekerprofiles/new.:format {:controller=>"jobseekerprofiles", :action=>"new"} | |
edit_jobseekerprofile GET /jobseekerprofiles/:id/edit {:controller=>"jobseekerprofiles", :action=>"edit"} | |
formatted_edit_jobseekerprofile GET /jobseekerprofiles/:id/edit.:format {:controller=>"jobseekerprofiles", :action=>"edit"} | |
tweetremove_jobseekerprofile GET /jobseekerprofiles/:id/tweetremove {:controller=>"jobseekerprofiles", :action=>"tweetremove"} | |
formatted_tweetremove_jobseekerprofile GET /jobseekerprofiles/:id/tweetremove.:format {:controller=>"jobseekerprofiles", :action=>"tweetremove"} | |
tweet_jobseekerprofile GET /jobseekerprofiles/:id/tweet {:controller=>"jobseekerprofiles", :action=>"tweet"} | |
formatted_tweet_jobseekerprofile GET /jobseekerprofiles/:id/tweet.:format {:controller=>"jobseekerprofiles", :action=>"tweet"} | |
tweetsend_jobseekerprofile GET /jobseekerprofiles/:id/tweetsend {:controller=>"jobseekerprofiles", :action=>"tweetsend"} | |
formatted_tweetsend_jobseekerprofile GET /jobseekerprofiles/:id/tweetsend.:format {:controller=>"jobseekerprofiles", :action=>"tweetsend"} | |
jobseekerprofile GET /jobseekerprofiles/:id {:controller=>"jobseekerprofiles", :action=>"show"} | |
formatted_jobseekerprofile GET /jobseekerprofiles/:id.:format {:controller=>"jobseekerprofiles", :action=>"show"} | |
PUT /jobseekerprofiles/:id {:controller=>"jobseekerprofiles", :action=>"update"} | |
PUT /jobseekerprofiles/:id.:format {:controller=>"jobseekerprofiles", :action=>"update"} | |
DELETE /jobseekerprofiles/:id {:controller=>"jobseekerprofiles", :action=>"destroy"} | |
DELETE /jobseekerprofiles/:id.:format {:controller=>"jobseekerprofiles", :action=>"destroy"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment