Mat*_*iby 2 ruby ruby-on-rails
我目前正在向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
Run Code Online (Sandbox Code Playgroud)
这是我的代码文件(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
Run Code Online (Sandbox Code Playgroud)
有什么想法会出错
从1.9.1 NEWS文件:
* Deprecated syntax
o colon (:) instead of "then" in if/unless or case expression.
Run Code Online (Sandbox Code Playgroud)
所以你不能再使用冒号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
Run Code Online (Sandbox Code Playgroud)
或换行:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3022 次 |
| 最近记录: |