0

我需要访问 AS400 文件中的字段。有一个与 400 的现有连接,现在我只需要使用与正在使用的文件不同的文件。

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

我需要用“C@OEF23L03”替换“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
4

1 回答 1

0

错误日志的第 2 行不是说第 59 行有语法错误吗?我在您包含的源代码中只看到 53 行,但也许您取出了一些。仔细查看语法错误消息,它似乎end在期待它标记为 $end 的东西时找到了关键字,我将其理解为它期待源代码结束。我不是 Ruby 程序员(或者至少还不是),但回顾你的源代码,似乎确实有一个额外end的东西似乎与任何东西都不匹配。还是要结束这堂课?

于 2013-04-12T00:17:31.720 回答