2013-04-11 2 views
0

AS400 파일에있는 필드에 액세스해야합니다. 400에 대한 기존 연결이 있으며 이제는 사용중인 파일과 다른 파일을 사용해야합니다.ROR을 사용하여 AS400 필드에 액세스

class Distributor < ActiveRecord::Base 

establish_connection "as400_#{RAILS_ENV}" 
set_table_name "DISTJ01" 

# TODO: what to return if no distributor? 
# Create array of hashed distributor info. 
def self.get_distributors_by_state state, preferred_distributor 
    d = [] 
    # see validate_distributor_number below 
    # If they have a preferred distributor, pull that one and make it first so it will default to that. 
    if !preferred_distributor.blank? 
     s = Distributor.find_by_sql ["SELECT CNAM05 cnam05, CUSNP1 cusnp1 FROM DISTJ01 WHERE CUSNP1 = ?", preferred_distributor] 
     d << { :name => s[0].cnam05, :id => s[0].cusnp1 } unless s.blank? 
    end 

    # If they have an account number, they can choose to purchase direct in addition to choosing a distributor. 
    # Per Ron 4/20/11, removed this. 
    #d << { :name => "DIRECT PURCHASE", :id => account_number } unless account_number.blank? 

    # Get all other available distributors for this state. 
    s = Distributor.find_by_sql ["SELECT CNAM05 cnam05, CUSNP1 cusnp1 FROM DISTJ01 WHERE STATEP2 = ? AND CUSNP1 <> ? ORDER BY CNAM05", state.upcase, preferred_distributor] 
    unless s.blank? 
     s.each do |t| 
      d << { :name => t.cnam05, :id => t.cusnp1 } 
     end 
    end 
    d 
end 

def self.validate_distributor_number distributor_number, user 
    # We need to make sure that the distributor number we are assigning 
    # is valid. Since it comes from a form post, somebody could pick 
    # another number if they wanted. We can't have that. Granted they 
    # already had to logon so they are a legit user, but, they still 
    # could try to trick us. 
    if distributor_number.strip == user.as400_fields[:account_number].strip 
     distributor_number 
    else 

     # If a DSD account chooses to purchase from their preferred distributor, we use the customer number from 
     # the sign-on table, not from the distributor. 
     if user.as400_fields[:preferred_distributor] == distributor_number and user.as400_fields[:account_type].strip == "DSD" 
      user.as400_fields[:account_number] 
     else 
      d = Distributor.find_by_sql ["SELECT CUSNP1 cusnp1 FROM DISTJ01, SIGNONS " + 
       "WHERE DISTJ01.STATEP2 = SIGNONS.BSSTCDW1 AND SIGNONS.USERW1 = ? AND DISTJ01.CUSNP1 = ?", user.login.upcase, distributor_number] 
      d[0].cusnp1 unless d.blank? 
     end 
    end 
end 

end 

나는 "OEF23L03 @ C" "와"DISTJ01 "를 교체 할 필요가 난 현장 EMAL23에 액세스해야하지만, 난 여전히 기존 연결 및 쿼리. 나는 단순히 스와핑 시도 기존의 파일이 필요하지만해야 그것이 작동하지 않기 때문에 그것을과 복잡함을 할 수있는 아이디어

이 오류 로그에서 다음과 같습니다.?

[Wed Apr 10 11:52:20 2013] [notice] Apache/2.2.14 (Ubuntu) Phusion_Passenger/3.0.1 configured -- resuming normal operations 
[ pid=14922 thr=77098160 file=utils.rb:176 time=2013-04-10 11:52:58.610 ]: *** Exception SyntaxError in PhusionPassenger::ClassicRails::ApplicationSpawner (/var/www /onlineordering.coastalpet.com/app/models/distributor.rb:59: syntax error, unexpected keyword_end,  expecting $end) (process 14922, thread #<Thread:0x930d960>): 
from <internal:lib/rubygems/custom_require>:29:in `require' 
from <internal:lib/rubygems/custom_require>:29:in `require' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:184:in `require' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:291:in `require_or_load' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:250:in `depend_on' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-2.3.10/lib/active_support/dependencies.rb:162:in `require_dependency' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:414:in `block (2 levels) in load_application_classes' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:413:in `each' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:413:in `block in load_application_classes' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:411:in `each' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:411:in `load_application_classes' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:197:in `process' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rails-2.3.10/lib/initializer.rb:113:in `run' 
from /var/www/onlineordering.coastalpet.com/config/environment.rb:6:in `<top (required)>' 
from <internal:lib/rubygems/custom_require>:29:in `require' 
from <internal:lib/rubygems/custom_require>:29:in `require' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/classic_rails/application_spawner.rb:222:in `preload_application' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/classic_rails/application_spawner.rb:181:in `block in initialize_server' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/utils.rb:564:in `report_app_init_status' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/classic_rails/application_spawner.rb:174:in `initialize_server' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:204:in `start_synchronously' 
from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.1/lib/phusion_passenger/abstract_server.rb:180:in `start' 
from /usr/local/ruby 

답변

0

라인 59에 구문 오류가 있다고 말하여 오류 로그의 2 라인되지 않습니다? 나는 당신이 포함시킨 소스에서 단지 53 줄을 보았을 지 모르지만, 아마 당신은 몇 줄을 꺼냈다. ntax 오류 메시지가 가까울수록 $ end라는 레이블이 붙을 것으로 예상 될 때 end이라는 키워드를 찾은 것 같습니다. 이는 소스의 끝을 예상한다는 의미입니다. 나는 루비 프로그래머가 아니다. (적어도 적어도 아직은 아니다.)하지만 당신의 소스를 되돌아 보면, 무엇이든 일치하지 않는 것으로 보이는 여분의 end이있는 것 같다. 아니면 수업을 끝내야합니까?

+0

페이지의 끝이라고 생각했지만 제거하려고합니다. –