Newbie Question : else if


#1

Hello, i have started using ruby on rails, and searched the web for
this information but found nothing!
My problem is : i have main.html.rb and inside a conditional :

<% if controller.controller_name == “main” %>

do something

<% else if controller.controller_name == “other_controller” %>

do something

<% else %>

do something

<% end %>

The problem is: im using netbeans and netbeans shows “Unexpected-end-
of-file” at the end in the close html tag.
So whats the problem? There is not else if tags in ror? If i use if -
else - end it runs fine but not if-else if-else-end.TIA


#2

try elsif

Simon


#3

2009/2/8 Julian L. removed_email_address@domain.invalid

Elsif

elsif is the way to do it, but why doesn’t ‘else if’ work? The ‘if’
being
the statement to be executed in the ‘else’ case


#4

Elsif

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/


#5

Hi, thanks for the reply, the problem is : when i use elseif and run
the program, i get an error saying that it cannot recognize elseif and
strangely all ruby code in netbeans color syntax is in blue but not
elseif statements?. This is what i get when running elseif :

undefined method `elseif’ for #ActionView::Base:0x21dae8c

Well, im using if (many_args) - end, if (many_args) - end for now.
Thanks for replying.


#6

There is only one e in elsif (not elseif). Don’t ask me why, one of the
few
annoying things in Ruby.

2009/2/8 wilson ikeda removed_email_address@domain.invalid


#7

On Feb 8, 1:55 pm, Colin L. removed_email_address@domain.invalid wrote:

2009/2/8 Julian L. removed_email_address@domain.invalid

Elsif

elsif is the way to do it, but why doesn’t ‘else if’ work? The ‘if’ being
the statement to be executed in the ‘else’ case

it does work, but

if foo

else if bla

end

isn’t valid (since the else has no matching end statement)
You’d need
if foo

else
if bla

end
end

Fred


#8

Hi,

All of the following are valid.
The third one is retarded, because by not putting the second if on a
new line, you don’t get the indentation, so you can’t visually tell if
you’ve got the right number of clauses. I prefer the fourth way.

Notice that the 3rd and 4th methods have an extra end, whereas the
second method has only one end.

if(true)
puts ‘yay’
else
puts ‘nay’
end

if(false)
puts ‘yay’
elsif(true)
puts ‘nay’
end

if(false)
puts ‘woo’
else if(true)
puts ‘boo’
end
end

if(false)
puts ‘woo’
else
if(true)
puts ‘boo’
end
end


#9

Not elseif
Elsif

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/