Case statements in views...strange error on OSX

I have a simple case statement in one of my views. This works fine on my
windows machine. Move to the mac and I get: “parse error, unexpected
tIDENTIFIER, expecting kWHEN”.

I have not changed anything but cannot resolve the issue. my view has
this in it (simplified for test)

<% case controller.controller_name -%>
<% when “accounts” -%>

worked accounts

<% else -%>

worked else

<% end -%>

I have reset the server everything. I’m using rails 1.1.1 and the latest
stable ruby build. Please help?

James W. wrote:

I have a simple case statement in one of my views. This works fine on my
windows machine. Move to the mac and I get: “parse error, unexpected
tIDENTIFIER, expecting kWHEN”.

I have not changed anything but cannot resolve the issue. my view has
this in it (simplified for test)

<% case controller.controller_name -%>
<% when “accounts” -%>

worked accounts

<% else -%>

worked else

<% end -%>

I have reset the server everything. I’m using rails 1.1.1 and the latest
stable ruby build. Please help?

Is it because I cannot split a case statement up like an if statement?

I’ve tested this code on Freebsd 5.3/Ruby 1.8/rails 1.0 and it runs fine
so i wouldn’t have thought it’s syntax…

Steve

James W. wrote:

Stephen B. wrote:

I’ve tested this code on Freebsd 5.3/Ruby 1.8/rails 1.0 and it runs fine
so i wouldn’t have thought it’s syntax…

Steve

Thanks Steve, still not working, really bugging me this is. Could
someone try on OSX to check ?

Still no joy there seems to be a direct problem with using case
statements in rails on OSX. Everything I try results in an error. Is
this linked to rails 1.1.1 ??

Stephen B. wrote:

I’ve tested this code on Freebsd 5.3/Ruby 1.8/rails 1.0 and it runs fine
so i wouldn’t have thought it’s syntax…

Steve

Thanks Steve, still not working, really bugging me this is. Could
someone try on OSX to check ?

James W. wrote:

James W. wrote:

Stephen B. wrote:

I’ve tested this code on Freebsd 5.3/Ruby 1.8/rails 1.0 and it runs fine
so i wouldn’t have thought it’s syntax…

Steve

Thanks Steve, still not working, really bugging me this is. Could
someone try on OSX to check ?

Still no joy there seems to be a direct problem with using case
statements in rails on OSX. Everything I try results in an error. Is
this linked to rails 1.1.1 ??

Has anyone used a case statement in a view without issue on OSX ?

Have you been retyping this in OSX, or are you still working with the
same file from your PC? Could it be a character set issue?

On Tuesday, April 25, 2006, at 4:48 PM, James W. wrote:

Still no joy there seems to be a direct problem with using case
statements in rails on OSX. Everything I try results in an error. Is
this linked to rails 1.1.1 ??


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

_Kevin

Kevin O. wrote:

Have you been retyping this in OSX, or are you still working with the
same file from your PC? Could it be a character set issue?

On Tuesday, April 25, 2006, at 4:48 PM, James W. wrote:

Still no joy there seems to be a direct problem with using case
statements in rails on OSX. Everything I try results in an error. Is
this linked to rails 1.1.1 ??


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

_Kevin

I have tried both. What I can now gather is that when you use a case
statement inside a view it does not like being written like this:
<% case controller.controller_name -%>
<% when “accounts” -%>

worked accounts

<% else -%>

worked else

<% end -%>

If I retype it like the example underneath it does not error but also
does not work, produces nothing. Yet on the PC it works fine.

<% case controller.controller_name
when “accounts”

worked accounts


else

worked else


end %>

What makes it even more interesting is that I wish to call a helper
method inside the case statement like this:

<% case controller.controller_name -%>

<% when “accounts” -%>

<%= sub_tab "Overview", :controller=>'accounts', :action => 

‘index’%>
<%= sub_tab “List Employees”, :controller=>‘accounts’, :action =>
‘list’ %>
<%= sub_tab “Roles & Permissions”, :controller=>‘accounts’, :action
=> ‘permissions’ %>

<% when “clients” -%>

<%= sub_tab "List Clients", :controller=>'clients', :action => 

‘index’ %>

<% else -%>

<%= sub_tab "Overview", :controller=>'projects', :action => 'index' 

%>

<% end -%>

Is there is another way to do what i’m trying to do without using case
statements?

On 4/25/06, Guest [email protected] wrote:

Has anyone used a case statement in a view without issue on OSX ?

I just tried a test, using OS X (10.4.6, Rails 1.1.2):

<% case @book.name -%>
<% when “book” %>
Is Book

<% else %>
Not Book

<% end %>

and it worked just fine.

jt

On 4/25/06, Guest [email protected] wrote:

Thanks jt. So I have a ruby or rails issue then. i am running the same
as you so that is really odd. here goes for an update.

That is an odd one. Can you do a case statement using irb?

irb(main):001:0> b=‘book’
=> “book”
irb(main):002:0> case b
irb(main):003:1> when ‘car’
irb(main):004:1> puts “is a car”
irb(main):005:1> when ‘book’
irb(main):006:1> puts “is a book”
irb(main):007:1> else
irb(main):008:1* puts “nothing”
irb(main):009:1> end
is a book

John T. wrote:

On 4/25/06, Guest [email protected] wrote:

Has anyone used a case statement in a view without issue on OSX ?

I just tried a test, using OS X (10.4.6, Rails 1.1.2):

<% case @book.name -%>
<% when “book” %>
Is Book

<% else %>
Not Book

<% end %>

and it worked just fine.

jt

Thanks jt. So I have a ruby or rails issue then. i am running the same
as you so that is really odd. here goes for an update.

John T. wrote:

On 4/25/06, Guest [email protected] wrote:

Thanks jt. So I have a ruby or rails issue then. i am running the same
as you so that is really odd. here goes for an update.

That is an odd one. Can you do a case statement using irb?

irb(main):001:0> b=‘book’
=> “book”
irb(main):002:0> case b
irb(main):003:1> when ‘car’
irb(main):004:1> puts “is a car”
irb(main):005:1> when ‘book’
irb(main):006:1> puts “is a book”
irb(main):007:1> else
irb(main):008:1* puts “nothing”
irb(main):009:1> end
is a book

That works fine. I have just updated ruby and rails to the latest
versions and it still does not work. I have created a new rails project
and just added this in the view:

Runme#index

Find me in app/views/runme/index.rhtml

<% case controller_controller_name %> <% when 'runme' %>

hello

<% else %>

not ok

<% end %>

This is the error I get:

SyntaxError in Runme#index

Showing app/views/runme/index.rhtml where line #3 raised:

compile error
script/…/config/…/app/views/runme/index.rhtml:3: parse error,
unexpected tIDENTIFIER, expecting kWHEN
case controller_controller_name ; _erbout.concat “\n”
^
script/…/config/…/app/views/runme/index.rhtml:4: parse error,
unexpected kWHEN, expecting kEND
when ‘runme’ ; _erbout.concat “\n”
^
script/…/config/…/app/views/runme/index.rhtml:10: parse error,
unexpected kEND, expecting $

Extracted source (around line #3):

1:

Runme#index


2:

Find me in app/views/runme/index.rhtml


3: <% case controller_controller_name %>
4: <% when ‘runme’ %>
5:

hello


6: <% else %>

Trace of template inclusion: /app/views/runme/index.rhtml

RAILS_ROOT: script/…/config/…
Application Trace | Framework Trace | Full Trace

#{RAILS_ROOT}/app/views/runme/index.rhtml:10:in `compile_template’

/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:305:in
compile_and_render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:290:in render_template’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:249:in
render_file' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:699:in render_file’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:621:in
render_with_no_layout' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/layout.rb:251:in render_without_benchmark’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:53:in
render' /usr/local/lib/ruby/1.8/benchmark.rb:293:in measure’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:53:in
render' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:911:in perform_action_without_filters’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:in
perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in perform_action_without_rescue’
/usr/local/lib/ruby/1.8/benchmark.rb:293:in measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in perform_action_without_rescue’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:in
perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in process_without_filters’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:in
process_without_session_management_support' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:in process’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in
dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in handle_dispatch’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:in
service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in start’
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in start’
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in start' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in dispatch’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick.rb:59
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
require' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in require’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require’
script/server:3

#{RAILS_ROOT}/app/views/runme/index.rhtml:10:in compile_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:305:in compile_and_render_template’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:290:in
render_template' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_view/base.rb:249:in render_file’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:699:in
render_file' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:621:in render_with_no_layout’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/layout.rb:251:in
render_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:53:in render’
/usr/local/lib/ruby/1.8/benchmark.rb:293:in measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:53:in render’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:911:in
perform_action_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:in perform_action_without_benchmark’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in measure’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:in perform_action’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in
process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:in process_without_session_management_support’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:in
process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in dispatch’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in
handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:in service’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in run’
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in start’
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in start’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in
dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in require’
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in
require' /usr/local/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in require’
script/server:3

Request

Parameters: None

Show session dump


flash: !map:ActionController::Flash::FlashHash {}

Response
Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}

I dont know what to do?

On 4/25/06, Guest [email protected] wrote:

Runme#index

Find me in app/views/runme/index.rhtml

<% case controller_controller_name %> <% when 'runme' %>

hello

<% else %>

not ok

<% end %>

Was that just a typeo? -

case controller.controller_name

What happens when you say:

<% case ‘runme’: %> instead of <% case ‘runme’ %>
?

Wilson B. wrote:

What happens when you say:

<% case ‘runme’: %> instead of <% case ‘runme’ %>
?

SOLVED !!!

It seems that you have to have the case and the first when on the same
ruby line e.g:

<% case controller.controller_name when ‘runme’ %>

instead of:

<% case controller.controller_name %>
<% when ‘runme’ %>

How strange is that, I thought that it would not matter? Anyway on with
the project…

On 4/25/06, Guest [email protected] wrote:

<% case controller.controller_name when ‘runme’ %>

instead of:

<% case controller.controller_name %>
<% when ‘runme’ %>

How strange is that, I thought that it would not matter? Anyway on with
the project…

Very odd.

As I posted above, this code works just fine in a test app in
show.rhtml:

<% case controller.controller_name -%>
<% when “books” %>
Is Book

<% else %>
Not Book

<% end %>

jt

I had this same problem yesterday. I’m on XP though, Ruby 1.8.4 mswin32,
and Rails 1.1.2. I found two ways around it:

  1. Encapsulate the whole case statement in <%= %>
  2. Encapsulate the first when with the case keyword, i.e.

<% b = :banana %>

<% case b
when String %>

It’s a string!

<% when Symbol %>

No it’s a symbol!

<% end %>