Anyone familiar with YAML and Ruby on Rails

14 views
Skip to first unread message

William Pattison

unread,
Jun 11, 2015, 9:39:21 PM6/11/15
to ic-...@googlegroups.com
I'm getting a line error on line 49, I'm not sure what I have done wrong, I'd appreciate any advice.

geemus (Wesley Beary)

unread,
Jun 16, 2015, 10:30:17 AM6/16/15
to ic-...@googlegroups.com
Nothing jumped out at me. At a guess maybe an unmatched pair of quotes or a non-quoted string with reserved character (or something like that). I'd check closely to make sure things have quotes on both ends and maybe add quotes to anything with non-ascii just in case. Might not fix it, but shouldn't hurt.

On Thu, Jun 11, 2015 at 8:39 PM, William Pattison <wi...@producerun.com> wrote:
I'm getting a line error on line 49, I'm not sure what I have done wrong, I'd appreciate any advice.

--

---
You received this message because you are subscribed to the Google Groups "Iowa City Ruby Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ic-ruby+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Rhinehart

unread,
Jun 16, 2015, 11:15:28 AM6/16/15
to ic-...@googlegroups.com
Remove the space in line 52:
from
\ "reports\"
to
 \"reports \"

also double quote line 155 because of the single quote in can't

William Pattison

unread,
Jun 16, 2015, 12:41:57 PM6/16/15
to ic-...@googlegroups.com
Thanks Wes and David,

I committed the  \"reports \" change and believe I've fixed that line error.

I may have made more than one error :(

I'll look out for those spaces between quotes etc.

Cheers,


Willliam Pattison
ProduceRun
Co-Founder / President

415 12th Avenue SE,
Cedar Rapids, IA 52401
USA Cell: +1 319 640 7002
Email: wi...@producerun.com
www.producerun.com

Follow my ProduceRun profile.

You received this message because you are subscribed to a topic in the Google Groups "Iowa City Ruby Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ic-ruby/xbzhKcrHg2I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ic-ruby+u...@googlegroups.com.

David Rhinehart

unread,
Jun 16, 2015, 12:43:56 PM6/16/15
to ic-...@googlegroups.com
Line 155 

"also double quote line 155 because of the single quote in can't"

William Pattison

unread,
Jun 16, 2015, 12:49:04 PM6/16/15
to ic-...@googlegroups.com
I removed ' from the can't to make the whole line blue.

Thanks again.

Willliam Pattison
ProduceRun
Co-Founder / President

415 12th Avenue SE,
Cedar Rapids, IA 52401
USA Cell: +1 319 640 7002
Email: wi...@producerun.com
www.producerun.com

Follow my ProduceRun profile.

Jordan Running

unread,
Jun 16, 2015, 5:22:56 PM6/16/15
to ic-...@googlegroups.com

As someone who works with YAML a lot (and rather likes it despite its, er, hazards), I have some unsolicited advice for everyone who uses YAML:

It’s not JSON. Don’t use quotation marks.

In my opinion YAML values should almost never be wrapped in quotation marks. In addition to adding line noise, as William discovered they can actually cause errors when you don’t match them up. There are only three situations in which your value should be wrapped in quotation marks (off the top of my head):

  1. It includes a colon (:) character. This is because colons separate mapping keys from their values, e.g. foo: 3. YAML doesn’t know what to do if it sees foo: bar: 3.
  2. It starts with [ or {. Those characters indicate the beginning of a flow (inline) sequence or mapping, respectively.
  3. It starts with %, & or *, which indicate a directive, anchor or alias, respectively.

“But wait,” you cry, “what about values that span multiple lines?” A good question, but in fact one of YAML’s best features is its features for dealing with this very thing. I’m going to use a little bit of William’s YAML to demonstrate; I hope he doesn’t mind:

dashboard_user_settings:
  # ...
  account_subtitle_html: "We need the below to make a financial transfer ..."

I’ve trimmed this so it won’t stretch anyone’s email window, but as it turns out we do need quotation marks around this value because there’s a colon later on. That’s a bummer, and it’s also a bummer that the value will scroll way off the side of our text editor.

But wait! We can express the same thing like this:

dashboard_user_settings:
  # ...
  account_subtitle_html: >
    We need the below to make a financial transfer date for successful
    projects. <b>ATENÇÃO: The tax details listed in the registration
    information and bank details must be the same.</b>

The > is the folded scalar indicator. “Scalar” is YAML-speak for “string.”. “Folded” means that every subsequent line with the same or greater level of indentation as the very next line will be “folded” into a single string with indentation and newlines removed. There is one slight difference, though: This string will end in a newline. If you want to strip the newline as well, use >- instead of >. (The - is a “block chomping indicator,” which you can read about in the YAML spec.)

“But wait,” you say, “what if I don’t want my string “folded”? What if, say, I have HTML with indentation I want to keep?” YAML has that covered, too. Instead of >, use | (pipe), which is the literal scalar indicator:

explanation_html: |
  <div class='fontsize-base u-marginbottom-40 card card-terciary'>
    <p class='fontweight-bold'>
      With the campaign published, some information may no longer
      be edited
    </p>
    ...
  </div>

The literal scalar indicator will leave interior newlines and indentation intact. What I mean by “interior” is that in the above code the whole block is indented two spaces, but YAML will “unindent” it, so the first and last lines have no leading spaces, the second line has two leading spaces instead of four, and so on. The same “chomping” rules apply, though, so if you don’t want a trailing newline, us |- instead of |.

As an exercise I’ve reformatted William’s YAML with these features in mind and put it in a Gist here: https://gist.github.com/jrunning/54ce15459c0a3985a8df If you click on “Revisions” on the right you can see a diff between the original and new versions.

Two final bits of advice: 1. Bookmark this online YAML parser, which will show you the result of your YAML as you type, which is great for learning and experimentation; and 2. Read the YAML spec. Okay, don’t read the whole thing, but do read sections 2, 6, 7 and 8.

Jordan
Chef Software, Inc.

Jordan Running

unread,
Jun 16, 2015, 5:32:22 PM6/16/15
to ic-...@googlegroups.com
TL;DR: Your YAML could look like this instead: https://gist.github.com/jrunning/54ce15459c0a3985a8df
...

Dennis Hoer

unread,
Jun 17, 2015, 11:11:28 AM6/17/15
to ic-...@googlegroups.com
Nice write up Jordan 

William Pattison

unread,
Jun 17, 2015, 11:56:57 PM6/17/15
to ic-...@googlegroups.com
Thanks for sharing your learning and advice Jordan, ProduceRun is open source so feel free to use it for examples.



Willliam Pattison
ProduceRun
Co-Founder / President

415 12th Avenue SE,
Cedar Rapids, IA 52401
USA Cell: +1 319 640 7002
Email: wi...@producerun.com
www.producerun.com

Follow my ProduceRun profile.

Reply all
Reply to author
Forward
0 new messages