On 1 August 2010 11:32, Dis Tec <lists@ruby-forum.com> wrote:
> I'm returning a value from the db which is true/false and I'd like to
> convert that to something more meaningful - how can I incorporate an if
> then into the inline html?
You can use conditional checking inline, with "normal" 'if...else' blocks:
<% if @my_object.active? %>
This is active
<% else %>
You need to activate this one
<% else %>
or you can use the ternary operator:
<%= @my_object.active? ? "This is active" : "You need to activate
this one" %>
or you can use 'if' conditions as guards:
<%= "This is active" if @my_object.active? %>
.... it all depends what's best for your situation.
And if you find yourself doing the same checks in a couple of places,
extract that out to a helper method to keep your code DRY.
> I have tried if ... puts "xxx", but to no avail.
What have you tried? (what was the *exact* line of code) And what was
the result that was "to no avail"? (the *exact* response - did
something appear; nothing; or an error?)
> Sorry, I'm a noobie and not quite got my head around this as yet or the
> error messages.
Try the following resource as a primer; it should help you organise
your requests for help to be more likely to elucidate responses:
http://catb.org/esr/faqs/smart-questions.html
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment