jastix (owner)

Revisions

gist: 98673 Download_button fork
public
Public Clone URL: git://gist.github.com/98673.git
Embed All Files: show embed
Ruby #
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
## Model :
class Theme < ActiveRecord::Base
....
has_attached_file :avtoref_doc
has_attached_file :avtoref_pdf
has_attached_file :disser_doc
has_attached_file :disser_pdf
has_attached_file :avtoref_swf
has_attached_file :disser_swf
has_scribdable_attachment :avtoref_pdf
has_scribdable_attachment :disser_pdf
has_scribdable_attachment :avtoref_doc
has_scribdable_attachment :disser_doc
validates_attachment_content_type :avtoref_doc, :content_type => 'application/msword'
validates_attachment_content_type :avtoref_pdf, :content_type => 'application/pdf'
validates_attachment_content_type :disser_doc, :content_type => 'application/msword'
validates_attachment_content_type :disser_pdf, :content_type => 'application/pdf'
validates_attachment_content_type :avtoref_swf, :content_type => 'application/x-swf'
validates_attachment_content_type :disser_swf, :content_type => 'application/x-swf'
if :avtoref_pdf == nil
validates_attachment_scribdability :avtoref_doc
elsif :avtoref_doc == nil
validates_attachment_scribdability :avtoref_pdf
end
 
if :disser_pdf == nil
validates_attachment_scribdability :disser_doc
elsif :disser_doc == nil
validates_attachment_scribdability :disser_pdf
end
 
## View (list.html.erb)
<% @themes.each do |t| %>
<tr class="<%= cycle("even","odd") %>">
...
<td valign=top><% if t.avtoref_pdf_scribd_id != nil %>
<%= link_to "Просмотр", {:controller => :themes, :action => :show_avtoref_pdf, :id => t.id}, :target => "_blank" %>
<% elsif t.avtoref_doc_scribd_id != nil %>
<%= link_to "Просмотр", {:controller => :themes, :action => :show_avtoref_doc, :id => t.id}, :target => "_blank" %>
<% end %></td>
<% if admin_do?(current_user) %>
 
<td valign=top><% if t.disser_pdf_scribd_id != nil %>
<%= link_to "Просмотр", {:controller => :themes, :action => :show_disser_pdf, :id => t.id}, :target => "_blank" %>
<% elsif t.disser_doc_scribd_id != nil%>
<%= link_to "Просмотр", {:controller => :themes, :action => :show_disser_doc, :id => t.id}, :target => "_blank" %>
<% end %></td>
 
## Views of documents
show_avtoref_doc.html.erb
<%= display_scribd(@theme, 'avtoref_doc') %>
show_avtoref_pdf.html.erb
<%= display_scribd(@theme, 'avtoref_pdf') %>
show_disser_doc.html.erb
<%= display_scribd(@theme, 'disser_doc') %>
show_disser_pdf.html.erb
<%= display_scribd(@theme, 'disser_pdf') %>
 
##Controllers
def show_avtoref_pdf
if current_user.blank? then redirect_to root_path
end
@theme = Theme.find(params[:id])
 
render :action => :show_avtoref_pdf# , :layout => false
end
 
def show_avtoref_doc
if current_user.blank? then redirect_to root_path
end
@theme = Theme.find(params[:id])
 
render :action => :show_avtoref_doc# , :layout => false
end
 
def show_disser_pdf
if current_user.blank? then redirect_to root_path
end
@theme = Theme.find(params[:id])
render :action => :show_disser_pdf# , :layout => false
end
 
def show_disser_doc
if current_user.blank? then redirect_to root_path
end
@theme = Theme.find(params[:id])
render :action => :show_disser_doc# , :layout => false
end
## Migrations
class AddScribd < ActiveRecord::Migration
def self.up
add_column :themes, :avtoref_pdf_scribd_id, :integer
add_column :themes, :avtoref_pdf_scribd_access_key, :string
add_column :themes, :disser_pdf_scribd_id, :integer
add_column :themes, :disser_pdf_scribd_access_key, :string
end
 
def self.down
remove_column :themes, :avtoref_pdf_scribd_id, :integer
remove_column :themes, :avtoref_pdf_scribd_access_key, :string
remove_column :themes, :disser_pdf_scribd_id, :integer
remove_column :themes, :disser_pdf_scribd_access_key, :string
end
end
 
class AddScribdDoc < ActiveRecord::Migration
def self.up
add_column :themes, :avtoref_doc_scribd_id, :integer
add_column :themes, :avtoref_doc_scribd_access_key, :string
add_column :themes, :disser_doc_scribd_id, :integer
add_column :themes, :disser_doc_scribd_access_key, :string
end
 
def self.down
remove_column :themes, :avtoref_doc_scribd_id, :integer
remove_column :themes, :avtoref_doc_scribd_access_key, :string
remove_column :themes, :disser_doc_scribd_id, :integer
remove_column :themes, :disser_doc_scribd_access_key, :string
end
end