我是 ruby on rails 的新手。我正在尝试从collection_action
ActiveAdmin 中调用一个类。这是代码(app/admin/models):
collection_action :status_race, :method => :post do
#Do some import work..
redirect_to :class => :import_route
end
这是我要调用的类的代码(app/lib/route):
class ImportRoute
def initialize
@seperator = " "
@time_format = "%d-%m-%y"
end
def run(filename)
puts "Running route import file"
raise "File" + filename + "doesn't not exist" unless File.exist(filename)
ri = RouteImporter.find(:name => self.class.name)
if(ri.nil?)
puts "Error, file doesn't exists"
end
CSV.foreach(filename, {:col_sep => @seperator}) do |row|
if row.lenght >5
ri.country_name = row[0] + " " + row[1]
ri.type = row[2]
ri.company = row [3]
else
ri.country_name = row[0]
ri.type = row[1]
ri.company = row[2]
ri.date = row[4].gsub(";", " ")
end
end
end
结尾
我曾经redirect_to
打电话给班级,但没有工作,而且我不知道该怎么做。任何的想法?谢谢!