Forum: Ruby on Rails Styling rails elements

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F29dea0c9c59cae430fa70ab70e4c08c?d=identicon&s=25 Ryan Ororie (bodegas411)
on 2009-01-06 21:54
I'm having some trouble with styling my views.

Here is a particular snippet that I think illustrates well:

<p><%= @tour_request.booked_datetime ? "<strong>Confirmed For:</strong>
<span class="red">#{@tour_request.booked_datetime_string}</span>
":"<strong>Date and time requested:</strong>
#{@tour_request.daterequested} | #{@tour_request.preferredtime_string}
<strong>Alternative date and time requested:</strong>
#{@tour_request.altdaterequested} #{@tour_request.preferredtime_string}"
%></p>

That will prevent the page from loading, showing a custom error screen.

But this, will display fine:

<p><%= @tour_request.booked_datetime ? "<strong>Confirmed For:</strong>
<strong>#{@tour_request.booked_datetime_string}</strong> ":"<strong>Date
and time requested:</strong> #{@tour_request.daterequested} |
#{@tour_request.preferredtime_string} <strong>Alternative date and time
requested:</strong> #{@tour_request.altdaterequested}
#{@tour_request.preferredtime_string}" %></p>

The only difference is on the first example I had <span
class="red">#{@tour_request.booked_datetime_string}</span> and the
second I had <strong>#{@tour_request.booked_datetime_string}</strong>

I know I could just do <span class="red"><%=
@tour_request.booked_datetime_string %> but this field won't always be
displaying, so I need to find a way to make whichever that particular
tour has filled out showing, whether it's booked_datetime_string,
tour_request.daterequested, preferredtime_string or altdaterequested

Would appreciate any help!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-07 01:35
(Received via mailing list)
On 6 Jan 2009, at 20:54, Ryan Ororie wrote:

> <strong>Alternative date and time requested:</strong>
> #{@tour_request.altdaterequested}
> #{@tour_request.preferredtime_string}"
> %></p>
>
> That will prevent the page from loading, showing a custom error
> screen.

At a basic level that code boils down to

"blahblahblah"red"blabblahblah"

which isn't syntactically correct (quotes in strings need to be escaped)

Fred
D6434aa0b7b350f8c3ed0119d81b2ead?d=identicon&s=25 Roy Pardee (rpardee)
on 2009-01-07 14:42
(Received via mailing list)
I think the first doublequote around "red" is terminating the string in
the first part of your ? : expresion.  If it were me, I'd verbose that
out some:

<% if @tour_request.booked_datetime then %>
  <p>
    <span class="label">Confirmed For:</span>
    <%= @tour_request.booked_datetime %>
  </p>
<% else %>
  <p>
    <span class="label">Date and time requested:</span>
    <%= @tour_request.daterequested %>
  </p>
<% end %>

That way you're not so much mixing the markup & the ruby, which always
winds up confusing me.

Also--having .booked_datetime and .booked_datetime_string methods seems
odd--consider writing a format_date helper to use to make dates pretty
if you need to get fancy.

HTH,

-Roy
This topic is locked and can not be replied to.