jmazzi (owner)

Fork Of

gist: 137148 by zukowskig Form post calls index inste...

Revisions

  • eced35 Sat Jun 27 16:01:34 -0700 2009
gist: 137170 Download_button fork
public
Public Clone URL: git://gist.github.com/137170.git
zukowskig form & controller
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
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
 
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
 
 
FORM
 
 
<%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 -%>