# Styling rails elements

**URL:** <https://www.ruby-forum.com/t/styling-rails-elements/157048>\
**Category:** Rails\
**Created:** [January 6, 2009, 9:54pm UTC](https://www.ruby-forum.com/t/styling-rails-elements/157048 "2009-01-06T21:54:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanoverton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@ryanoverton](https://www.ruby-forum.com/u/ryanoverton)\
**Post date:** [January 6, 2009, 9:54pm UTC](https://www.ruby-forum.com/t/styling-rails-elements/157048/1 "2009-01-06T21:54:41Z")

</div>

I’m having some trouble with styling my views.

Here is a particular snippet that I think illustrates well:

\<%= @tour\_request.booked\_datetime ? " **Confirmed For:** #{@tour\_request.booked\_datetime\_string} ":" **Date and time requested:** #{@tour\_request.daterequested} | #{@tour\_request.preferredtime\_string} **Alternative date and time requested:** #{@tour\_request.altdaterequested} #{@tour\_request.preferredtime\_string}" %\>

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

But this, will display fine:

\<%= @tour\_request.booked\_datetime ? " **Confirmed For:**** #{@tour\_request.booked\_datetime\_string} **":"** Date and time requested: **#{@tour\_request.daterequested} | #{@tour\_request.preferredtime\_string}** Alternative date and time requested:** #{@tour\_request.altdaterequested} #{@tour\_request.preferredtime\_string}" %\>

The only difference is on the first example I had #{@tour\_request.booked\_datetime\_string} and the  
second I had **#{@tour\_request.booked\_datetime\_string}**

I know I could just do \<%=  
 @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!

---

<div class="post-metadata">

**Author:** ![ryanoverton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@ryanoverton](https://www.ruby-forum.com/u/ryanoverton)\
**Post date:** [January 7, 2009, 1:35am UTC](https://www.ruby-forum.com/t/styling-rails-elements/157048/2 "2009-01-07T01:35:03Z")

</div>

On 6 Jan 2009, at 20:54, Ryan O. wrote:

> **Alternative date and time requested:**  
> #{@tour\_request.altdaterequested}  
> #{@tour\_request.preferredtime\_string}"  
> %\>
> 
> 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

---

<div class="post-metadata">

**Author:** ![ryanoverton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ea924/32.png) [@ryanoverton](https://www.ruby-forum.com/u/ryanoverton)\
**Post date:** [January 7, 2009, 2:42pm UTC](https://www.ruby-forum.com/t/styling-rails-elements/157048/3 "2009-01-07T14:42:53Z")

</div>

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 %\>

Confirmed For: \<%= @tour\_request.booked\_datetime %\>

\<% else %\> 

Date and time requested: \<%= @tour\_request.daterequested %\>

\<% 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
