> On Dec 16, 2017, at 6:34 PM, Sam Ruby <ru...@intertwingly.net> wrote:
> 
>> The code in the existing main.rb in get '/invite' sets several variables 
>> that will be useful in discuss and vote. DRY says this code should only be 
>> in one place. How can variables be shared among multiple get and post paths?
> 
> Two basic approaches come to mind.  In the roster tool, there is code
> in the models directory that return hashes.  Also in
> www/roster/main.rb, you can find a helper that is called by multiple
> views.

What I'm trying to do is to get the @pmcs and @ppmcs variables sent to the view 
from discuss, vote, and invite. The roster example shows no variables outside 
the do... end blocks. The code to calculate these is simple but not trivial. 

So would you recommend doing the calculation in the common code and setting the 
@variables in the do... end block. E.g.

  pmcs = ASF::Committee.pmcs.map(&:name).sort
  ppmcs = ASF::Podling.list
    .select {|podling| podling.status == 'current'}
    .map(&:name).sort

get '/discuss' do
  @view = 'discuss'
  @pmcs = pmcs
  @ppmcs = ppmcs
  _html :app
end

get '/vote' do
  @view = 'vote'
  @pmcs = pmcs
  @ppmcs = ppmcs
  _html :app
end

Craig L Russell
Secretary, Apache Software Foundation
c...@apache.org http://db.apache.org/jdo

Reply via email to