ruby embedded conditionals

12 बार देखा गया
नहीं पढ़े गए पहले मैसेज पर जाएं

Joe Guerra

नहीं पढ़ी गई,
9 फ़र॰ 2017, 12:10:53 pm9/2/17
ईमेल पाने वाला Ruby on Rails: Talk
I can't get my embedded  if statement working  in a html table.

here's one row of my table from my cart index...

<td><%= cart.created_at.strftime("%m/%d/%Y")    %> |  <%=  cart.product_id  %> |  <% if cart.processing == 'true'%> <%= Processing order %>  <% end %></td>

basically I want to indicate when an item is being processed in the cart... 

Norm Scherer

नहीं पढ़ी गई,
9 फ़र॰ 2017, 12:26:01 pm9/2/17
ईमेल पाने वाला rubyonra...@googlegroups.com
Is cart.processing really a string?  I would expect it to be boolean where you might compare it to true or just have <% if cart.processing %>

Norm
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2ccbb634-511f-429d-a1d6-4da025344834%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Colin Law

नहीं पढ़ी गई,
9 फ़र॰ 2017, 12:30:31 pm9/2/17
ईमेल पाने वाला Ruby on Rails: Talk
On 9 February 2017 at 17:10, Joe Guerra <jgu...@jginfosys.com> wrote:
> I can't get my embedded if statement working in a html table.
>
> here's one row of my table from my cart index...
>
> <td><%= cart.created_at.strftime("%m/%d/%Y") %> | <%= cart.product_id
> %> | <% if cart.processing == 'true'%> <%= Processing order %> <% end
> %></td>

You should not have the <%= %> round Processing order as that is not ruby, so
<% if cart.processing == 'true'%>Processing order<% end %>
but possibly better
<%= "Processing order" if cart.processing == 'true' %>
That is assuming that cart.processing is a string not a boolean.

I suspect your original code would have shown an error in the console
and development.log, in which case it is always a good idea to post
the error when asking for help.

Colin

Joe Guerra

नहीं पढ़ी गई,
9 फ़र॰ 2017, 12:34:41 pm9/2/17
ईमेल पाने वाला Ruby on Rails: Talk
It is a boolean value, I did get it to work.  

Rob Biedenharn

नहीं पढ़ी गई,
9 फ़र॰ 2017, 1:02:54 pm9/2/17
ईमेल पाने वाला rubyonra...@googlegroups.com
Try it like this:
<td><%= cart.created_at.strftime("%m/%d/%Y") %> | <%= cart.product_id %> | <%= 'Processing order' if cart.processing == 'true'%></td>
Also, why is cart.processing returning a string? (Or why are you testing the value is 'true'?) It would be more natural to have cart.processing? be truthy.

-Rob
सभी प्रषकों को उत्तर दें
लेखक को उत्तर दें
आगे भेजें
0 नया मैसेज