## 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