Forum: Ruby on Rails Is "case" a magic name

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2005-12-22 01:39
(Received via mailing list)
I'm a newbie.

My first app is using a table called cases.  With just "scaffold
:case" I get the basic list to show up.

I just did a "generate scaffold case case"  (I think that is correct).

Now when I try to list my cases, I'm getting a syntax error on all of
the view source code that references "case".

ie. <% for case in @cases %>

Thanks
Greg
--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century
7f75a9ab7ef058b2e7aafa89bc20eea2?d=identicon&s=25 Chris Grant (Guest)
on 2005-12-22 01:51
(Received via mailing list)
'case' is a Ruby reserved word.

-Chris
Cee0292fffa691f1fb320d5400200e99?d=identicon&s=25 Marcel Molina Jr. (Guest)
on 2005-12-22 01:54
(Received via mailing list)
On Wed, Dec 21, 2005 at 07:37:51PM -0500, Greg Freemyer wrote:
> ie. <% for case in @cases %>
Yes, 'case' is part of Ruby's syntax.

  answer = 'yes'
  case answer
    when 'yes'
      # ...
    when 'no
      # ...
  end

marcel
5fc52b212d554dd8e0337bf27a5187f3?d=identicon&s=25 Lee Marlow (Guest)
on 2005-12-22 01:54
(Received via mailing list)
"case" is used for switch statements in Ruby.

Try renaming your local variable and see if it works.

<% for a_case in @cases %>
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2005-12-22 18:32
(Received via mailing list)
On 12/21/05, Lee Marlow <lee.marlow@gmail.com> wrote:
> "case" is used for switch statements in Ruby.
>
> Try renaming your local variable and see if it works.
>
> <% for a_case in @cases %>
>
Works like a champ.

Will having a table called cases give me ongoing problems, or is it
safe to proceed like this?

Thanks
Greg
--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century
This topic is locked and can not be replied to.