Victor Pudeyev
Victor Pudeyev

Reputation: 4539

Weird ruby syntax error

I get this code generated for scaffold:

assert_difference('Day.count') do
  post :create, day: @day.attributes
end

you see? It's not :day => @day.attributes, it's day: @day.attributes. One of my two dev environments doesn't complain, another one complains, and production doesn't complain. Am I going crazy?

Upvotes: 1

Views: 107

Answers (3)

sarnold
sarnold

Reputation: 104050

I expect one of your environments is using Ruby 1.9.2, and one environment is on an older version of Ruby.

What you're seeing is a form of named parameters (sometimes known as "keyword parameters") that provides syntactic sugar around the older hash mechanism that almost provided named parameters.

Upvotes: 2

Nick Coelius
Nick Coelius

Reputation: 4746

That's just new ruby 1.9 syntax. You can track ruby syntax changes at eigenclass.org :-)

EDIT: Which seems to be malformed somehow. Interesting.

Upvotes: 0

numbers1311407
numbers1311407

Reputation: 34072

That's the newer ruby 1.9 hash syntax. Personally, I never made the switch. The good old arrows are fine with me. One of your environments apparently doesn't support it.

Upvotes: 0

Related Questions