"Posso nunca chegar a ser o melhor engenheiro do mundo, mas tenha certeza de
que eu vou lutar com todas as minhas forças para ser o melhor engenheiro que
eu puder ser"
I can't see what your specific error is, but that structure will at least be easier to read and debug.
Also, any logic you can move to a controller - out of the <% erb %> - move it there. Or better, into a model. The view should have the minimum possible logic.
if 1==1 then 'a' elsif 'a'=='a' then 'b' else 'c' end
=> "a"
if 1==2 then 'a' elsif 'a'=='b' then 'b' else 'c' end
=> "c"
With a cursory glance, I can only guess that your first condition is
always true. Maybe somebody could pipe in about ERB if that's a
factor, because I'm not familiar with it.
Todd
···
On Sat, Aug 16, 2008 at 10:09 PM, Luiz Vitor Martinez Cardoso <grabber@gmail.com> wrote:
require 'erb'
puts "Insert a number"
n = gets.to_i
str = '<%= if n%3 == 0 then "divisible by three";elsif n%2==0 then "divisible by two";end%>'
puts ERB.new(str).result
Entering 3 gives "divisible by 3", while entering 2 gives "divisible by two".
Stefano
···
On Sunday 17 August 2008, Luiz Vitor Martinez Cardoso wrote:
<% if @recipes.length == (i+1) then @id = 0 ; elsif
i.remainder(2) == 1 then @id = 1 ; else @id = 2 end >%
But in my tests the elsif condition is totally ignored, why?
Thanks for you attention!
Ideally, even this rather trivial code is best left outside of ERB files. Hide this away in a function and it can be as clean and multi-liney as you want and doesn't muck up your ERB files. This is doubleplus true if this code is used more than once. Cramming the entire if statement onto line just makes it less readable.
···
--
Michael Morin
Guide to Ruby
Become an About.com Guide: beaguide.about.com
About.com is part of the New York Times Company
@id = case when @recipes.length == i + 1: 0; when i.remainder(2) == 1: 1; else 2 end
Although I admit that I'd rather have it on several lines
I suspect the original posted might not know you can write a multi-line
<% erb %> block! Some sample code puts a different <% %> on each line,
like the original post did...
On Sun, Aug 17, 2008 at 10:11 AM, Phlip <phlip2005@gmail.com> wrote:
@id = case when @recipes.length == i + 1: 0; when i.remainder(2) == 1: 1;
else 2 end
Although I admit that I'd rather have it on several lines
I suspect the original posted might not know you can write a multi-line
<% erb %> block! Some sample code puts a different <% %> on each line,
like the original post did...
"Posso nunca chegar a ser o melhor engenheiro do mundo, mas tenha certeza de
que eu vou lutar com todas as minhas forças para ser o melhor engenheiro que
eu puder ser"
"Posso nunca chegar a ser o melhor engenheiro do mundo, mas tenha certeza de
que eu vou lutar com todas as minhas forças para ser o melhor engenheiro que
eu puder ser"