嗨,所以我在我的视图上使用了一个辅助模块来运行一些功能......但不知何故,这部分辅助代码出现在我的 html 上..
for i in 0..minedTextSize
这是在 html
这是调用 helper 方法的 html。
<h1>TEST TEST</h1>
<%=extract_value("filePath")%>
在我的控制器中,我只包含了辅助方法
class MainPageController < ApplicationController
include ExtractHelper
def index
end
end
有任何想法吗?
更新########
这是我的帮手 ruby 代码
module ExtractHelper
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'pdf-reader-turtletext'
def download_pdf(url)
found = false
page = Nokogiri::HTML(open("http//www.somesite.com")
puts page.class # => Nokogiri::HTML::Documents
for i in 0..(page.css('a').size - 1)
if(page.css('a')[i]['href'][-4,4] != ".pdf")
next
else
found = true
file_link = page.css('a')[i]['href']
file_link.gsub!(' ','%20')
link = "http//www.somesite.com/" + file_link # Generate the $
puts link
download = open(link)
IO.copy_stream(download,"/home/ec2user/my_project/pdfFiles/Demo.pdf")
puts file_link + " has been downloaded."
@link = file_link + " has been downloaded."
if found == true
break
end
end #if
end # for
end #def
def extract_value(filePath)
filePath = "/home/ec2-user/my_project/pdfFiles/Demo.pdf"
reader = PDF::Reader::Turtletext.new(filePath)
textangle = reader.bounding_box do
inclusive true
page 4
below "RIGHT HERE"
end
minedText = textangle.text
minedTextSize = minedText.size - 1
for i in 0..minedTextSize
if minedText[i][0].include? "WEEK 1"
puts minedText[i][1]
@lastweek = minedText[i][1]
end
if minedText[i][0].include? "WEEK 2"
puts minedText[i][1]
@previousweek = minedText[i][1]
end
end
end #def
end #module
将打印输出到stdout。您在视图中得到 0..36,因为 helper 正在返回其最后一个评估行(a for)的值。尝试明确评估/返回某些内容,例如:
def extract_value(filePath)
# some initial code
value = ''
for i in 0..minedTextSize
# some more code
value = 'something'
end
"String concatenating some #{value}"
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句