Как я получаю доступ к среде Стойки из направляющих?

Вы можете использовать цикл for для просмотра всех данных и иметь переменную-счетчик для всех 9 пунктов назначения. Используйте Сплит, чтобы получить правильные данные из данных. Вот некоторый псевдокод, который может вам помочь:

HourVariable = 0
For i = 1 to endOfdata
  dHour = split(split(dataline(i),"|")(1),":")(0) 'Get the hour from the dataline
  If Hourvariable <> dHour then 'Check if the hour changed. In that case the data for that hour needs to be written and all counters go to 0
     If cKitchen > 0 then NewData = NewData & "|" & dHour & "|" & cKitchen & "|Kitchen|" & vbNewLine
     If cBedroom > 0 etc...    
     cKitchen = 0
     cBedroom = 0
     HourVariable = dHour
     Select case split(dataline(i),"|")(3) 'Check which destination is in the current dataline
       Case "Kitchen": cKitchen = cKitchen + 1
       Case "Bedroom": etc...
     End Select
  Else 'In other cases, just add to the counters
     Select case split(dataline(i),"|")(3) 'Check which destination is in the current dataline
       Case "Kitchen": cKitchen = cKitchen + 1
       Case "Bedroom": etc...
     End Select
  End if
next i
31
задан Michael Gundlach 12 May 2009 в 14:51
поделиться

1 ответ

Я почти уверен, что вы можете использовать объект Rack :: Request для передачи переменных области запроса:

# middleware:
def call(env)
  request = Rack::Request.new(env) # no matter how many times you do 'new' you always get the same object
  request[:foo] = 'bar'
  @app.call(env)
end

# Controller:
def index
  if params[:foo] == 'bar'
    ...
  end
end

В качестве альтернативы вы можете получить " ] env "объект напрямую:

# middleware:
def call(env)
  env['foo'] = 'bar'
  @app.call(env)
end

# controller:
def index
  if request.env['foo'] == 'bar'
    ...
  end
end
27
ответ дан 27 November 2019 в 22:26
поделиться
Другие вопросы по тегам:

Похожие вопросы: