Hi --
ehm great
if true then
@users = User.find( :all )
else
@users = User.find( :all )
end if
1
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
works, but commenting out 1
if true then
@users = User.find( :all )
else
@users = User.find( :all )
end if
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
makes the if not evaluated.
why?
$ ruby -e 'if true then p 1 else p 2 end if false'
$ ruby -e 'if true then p 1 else p 2 end if true'
1
The "if false" and "if true" at the end govern the whole thing. In
your first example, you're doing:
if true then @users = ... else @users = ... end if 1
Since 1 is true, it gets executed.
In your second example, you're doing:
if true then @users = ... else @users = ... end if respond_to...
I imagine respond_to must return nil. Therefore, you're telling the
first if statement not to execute.
This "if <condition> end if <other_condition>" idiom is extremely
unusual and almost certainly not what you intend to do. As others have
said, it looks like you just want an if block, which ends with end.
David
--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
INTRO TO RAILS June 24-27 London (Skills Matter)
See
http://www.rubypal.com for details and updates!