我目前正在向heroku部署rails应用程序。该应用程序是rails 2.3.3,由于某种原因可能因为它不同的ruby我没有得到一个奇怪的语法错误
这是我的错误
Downloading postal codes.
rake aborted!
/app/app/models/postal_code.rb:13: syntax error, unexpected ':', expecting keyword_then or ',' or ';' or '\n'
when Integer: first(:conditions => { :code => code })
^
/app/app/models/postal_code.rb:14: syntax error, unexpected keyword_when, expecting keyword_end
when Hash: first(:conditions => {...
^
/app/app/models/postal_code.rb:59: syntax error, unexpected keyword_end, expecting $end
这是我的代码文件(postal_code.rb)
11 def self.get(code)
12 case code
13 when Integer: first(:conditions => { :code => code })
14 when Hash: first(:conditions => { :city => code[:city], :state => code[:state] })
15 else raise InternalException.new("Invalid input.")
16 end
17 end
51 # now set min and max lat and long accordingly
52 area[:min_lat] = latitude - area[:lat_degrees]
53 area[:max_lat] = latitude + area[:lat_degrees]
54 area[:min_lon] = longitude - area[:lon_degrees]
55 area[:max_lon] = longitude + area[:lon_degrees]
56
57 area
58 end
任何想法是什么出错?
答案 0 :(得分:6)
来自1.9.1 NEWS文件:
* Deprecated syntax
o colon (:) instead of "then" in if/unless or case expression.
因此,您不能再使用带有case
的冒号。您可以使用then
:
case code
when Integer then first(:conditions => { :code => code })
when Hash then first(:conditions => { :city => code[:city], :state => code[:state] })
else raise InternalException.new("Invalid input.")
end
或换行:
case code
when Integer
first(:conditions => { :code => code })
when Hash
first(:conditions => { :city => code[:city], :state => code[:state] })
else
raise InternalException.new("Invalid input.")
end
答案 1 :(得分:2)
这应该有效:
def self.get(code)
case code
when Integer then first(:conditions => { :code => code })
when Hash then first(:conditions => { :city => code[:city], :state => code[:state] })
else raise InternalException.new("Invalid input.")
end
end