archive/app/helpers/admin/archive_files_helper.rb

29 lines
1.1 KiB
Ruby

module Admin::ArchiveFilesHelper
def page_for_archive_file(archive_file, full_url=false)
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
archive_file_page = pages.first if archive_file_page.nil?
end
if full_url
request.protocol+(request.host_with_port+archive_file_page.url+'/'+archive_file.to_param).gsub('//','/') rescue "#"
else
"#{archive_file_page.url}?title=#{archive_file.title}"
end
end
end