开发者

Rails 3 syntax error in development when line is split into multiple lines in controller

开发者 https://www.devze.com 2023-04-06 13:02 出处:网络
When I was developing my project on my local file I had this line in code which worked correctly: @json = Location.qty_of_deliv_from(params[:from_rc])

When I was developing my project on my local file I had this line in code which worked correctly:

@json = Location.qty_of_deliv_from(params[:from_rc])
  .qty_of_deliv_to(params[:to_rc])

When I deployd with passenger I get a syntax error 开发者_如何学Goon this line which goes avay if I have all the code in the same line:

@json = Location.qty_of_deliv_from(params[:from_rc]).qty_of_deliv_to(params[:to_rc])

Is this a known issue?


Perhaps your server's ruby version is different and parses differently?

In any case, in Ruby, when writing multiline code you typically want to make sure your lines to be wrapped are syntactically incomplete, so as not to confuse the parser, e.g. by using a hanging dot, instead.

Location.qty_of_deliv_from(params[:form_rc]).
  qty_of_deliv_to(params[:to_rc])

Or you can use the backslash to escape the new line:

Location.qty_of_deliv_from(params[:form_rc]) \
  .qty_of_deliv_to(params[:to_rc])
0

精彩评论

暂无评论...
验证码 换一张
取 消