-
Notifications
You must be signed in to change notification settings - Fork 0
/
Photo_uploads_homework.txt
96 lines (69 loc) · 3.57 KB
/
Photo_uploads_homework.txt
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
1.Model: student.rb
def image_file=(input_data)
return if input_data.blank?
self.photo_filename = input_data.original_filename
self.photo_content_type = input_data.content_type.chomp
self.photo_data = input_data.read
end
Db:table:students
# photo_filename :string(255)
# photo_content_type :string(255)
# photo_data :binary(16777215
Table name: archived_students
# photo_filename :string(255)
# photo_content_type :string(255)
# photo_data :binary(16777215)
2.Controller: student_controller
def show
@student = Student.find_by_admission_no(params[:id])
send_data(@student.photo_data,
:type => @student.photo_content_type,
:filename => @student.photo_filename,
:disposition => 'inline')
end
3.app/views/student: show.rhtml
<% unless @student.photo_data.blank? %>
<%= image_tag(url_for({:controller => 'student', :action =>
'show', :id => @student.id}))%>
<% end %>
4.app/views/student: show_previous_details.rhtml
<div id="profile_picture_display">
<% unless @student.photo_data.blank? %>
<img src="<%= url_for(:controller=>"student", :action => "show", :id => @student.admission_no) %>" />
<% else %>
<%= image_tag "master_student/profile/topbanner.png" %>
<% end %>
</div>
5.app/views/student: profile.rhtml
<div id="profile_picture_display">
<% unless @student.photo_data.blank? %>
<img src="<%= url_for(:controller=>"student", :action => "show", :id => @student.admission_no) %>" />
<% else %>
<%= image_tag "master_student/profile/default_student.png" %>
<% end %>
</div>
6.app/views/archived_student: profile.rhtml
<div id="profile_picture_display">
<% unless @archived_student.photo_data.blank? %>
<img src="<%= url_for(:controller=>"student", :action => "show", :id => @archived_student.admission_no) %>" />
<% else %>
<%= image_tag "master_student/profile/topbanner.png" %>
<% end %>
</div>
7.app/views/student: edit.rhtml
<span class="span-sub-heading">Upload User photo</span>
<hr class="sub-heading"></hr>
<div class="label-field-pair">
<label for="master_student_image_file">Upload photo (50KB max)</label>
<div class="text-input-bg"><%= s.file_field :image_file %></div>
</div>
8.views/student/admission1.html.erb
<script>
(function($){$.fn.filestyle=function(options){var settings={width:250};if(options){$.extend(settings,options);};return this.each(function(){var self=this;var wrapper=$("<div>").css({"width":settings.imagewidth+"px","height":settings.imageheight+"px","background":"url("+settings.image+") 0 0 no-repeat","background-position":"right","display":"inline","position":"absolute","overflow":"hidden"});var filename=$('<input class="file">').addClass($(self).attr("class")).css({"display":"inline","width":settings.width+"px"});$(self).before(filename);$(self).wrap(wrapper);$(self).css({"position":"relative","height":settings.imageheight+"px","width":settings.width+"px","display":"inline","cursor":"pointer","opacity":"0.0"});if($.browser.mozilla){if(/Win/.test(navigator.platform)){$(self).css("margin-left","-142px");}else{$(self).css("margin-left","-168px");};}else{$(self).css("margin-left",settings.imagewidth-settings.width+"px");};$(self).bind("change",function(){filename.val($(self).val());});});};})(jQuery);
</script>
<span class="span-sub-heading">Upload User Photo</span>
<hr class="sub-heading"></hr>
<div class="label-field-pair">
<label for="student_image_file">Upload photo (50KB max)</label>
<div class="text-input-bg"><%= s.file_field :image_file %></div>
</div>