语法错误,意外的keyword_else,期待')'

时间:2014-05-13 19:37:21

标签: ruby ruby-on-rails-3

运行以下代码时出现此错误:

/home/deployer/loadmax/releases/20140512215519/lib/primeloads.rb:53: syntax error, unexpected keyword_else, expecting ')'
/home/deployer/loadmax/releases/20140512215519/lib/primeloads.rb:58: syntax error, unexpected tIDENTIFIER, expecting ')'
        record[:length] = "#{post["Trailer"]}"
              ^
/home/deployer/loadmax/releases/20140512215519/lib/primeloads.rb:103: syntax error, unexpected keyword_end, expecting $end
/home/deployer/loadmax/releases/20140512215519/lib/tasks/primeloads.rake:1:in `require_relative'
/home/deployer/loadmax/releases/20140512215519/lib/tasks/primeloads.rake:1:in `<top (required)>'

以下是代码:

40    def build_post(array_of_post_hashes, serial_number)
41      #checks to see if compatible file types
42      @posts = array_of_post_hashes.keep_if {|x| x.keys.include? "type" }
43      @posts.each do |post|
44        record = {
45          equipment_id: self.set_equipment(post["Load"]),
46          comments: self.set_comments(post["Order"])
47        }
48        record[:user_id] = '10181'
49        record[:origin] = "#{post["Origin"]}, #{post["Origin_State"]}"
50        record[:dest] = "#{post["Destination"]}, #{post["Destination_State"]}"

如果givin日期大于或等于&#34; 2014-5-13 00:00:00&#34;然后发布给定日期

其他发布时间日期

51        if Chronic.parse(#{post["Pickup_Date"]}) >= Chronic.parse('today').strftime('%Y-%m-%d 00:00:00')
52          record[:pickup] = Chronic.parse(#{post["Pickup_Date"]})
53        else
54          record[:pickup] = Chronic.parse('now')
55        end
56        record[:delivery] = Chronic.parse(#{post["Delivery_Date"]}) 
57        record[:rate] = 'CALL'
58        record[:length] = "#{post["Trailer"]}"
59        record[:hotload] = 'True'
60        @log.debug "POSTED #{post["Order"]}"
61        begin
62          Resque.enqueue(MajorPoster,record)
63        rescue Exception => e
63          @log.error e
65        end
66      end
67    end

解析文件

Order,Origin,Origin_State,Destination,Destination_State,Pickup_Date,Delivery_Date,Load,Trailer,Contact_Number
9014172,Santa Teresa,NM,La Grange,GA,7/9/2014,7/12/2014,VR,53,800-833-8616
9016365,Santa Teresa,NM,Seymour,IN,7/9/2014,7/12/2014,VR,53,800-833-8616
9014795,Santa Teresa,NM,Coldwater,MI,7/9/2014,7/12/2014,VR,53,800-833-8616
9014998,Santa Teresa,NM,Grove City,OH,7/9/2014,7/12/2014,VR,53,800-833-8616
9015417,Santa Teresa,NM,Menomonie,WI,7/9/2014,7/12/2014,VR,53,800-833-8616
9015415,Santa Teresa,NM,Hope Mills,NC,7/8/2014,7/12/2014,VR,53,800-833-8616

1 个答案:

答案 0 :(得分:2)

更改行

# syntactically invalid ruby code.
record[:pickup] = Chronic.parse(#{post["Pickup_Date"]})

record[:pickup] = Chronic.parse(post["Pickup_Date"])

这里你不需要字符串插值。有很多这样的错误,去修复它。如果需要,请以record[:delivery] = Chronic.parse("#{post['Delivery_Date']}")正确的方式编写。