archive/app/helpers/admin/archive_files_helper.rb

25 lines
1014 B
Ruby

module Admin::ArchiveFilesHelper
def page_for_archive_file(archive_file)
archive_file_page = nil
pages = Page.where(:module=>'archive').select{|page| page.enabled_for.include?(I18n.locale.to_s)}
pages.each do |page|
if page.categories.count ==1
if (page.categories.include?(archive_file.category.id.to_s) rescue false)
archive_file_page = page
end
end
break if !archive_file_page.nil?
end
if archive_file_page.nil?
pages.each do |page|
if (page.categories.include?(archive_file.category.id.to_s) rescue false)
archive_file_page = page
end
break if !archive_file_page.nil?
end
end
archive_file_page = pages.first if archive_file_page.nil?
request.protocol+(request.host_with_port+archive_file_page.url+'/'+archive_file.to_param).gsub('//','/') rescue "#"
end
end