# How to specify css

**URL:** <https://www.ruby-forum.com/t/how-to-specify-css/170823>\
**Category:** Rails\
**Created:** [June 23, 2009, 8:10am UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823 "2009-06-23T08:10:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 23, 2009, 8:10am UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/1 "2009-06-23T08:10:50Z")

</div>

Hi…  
i used paulca-phone\_codes plugin for country code.and it works.  
\<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix)%\>  
what i want to know is how to apply css class for this.when i tried like  
below it doesnot work  
\<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix),  
{:class =\> “mystyle” }%\>

Any helps

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 23, 2009, 9:12am UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/2 "2009-06-23T09:12:08Z")

</div>

Newb N. wrote:

> Hi…  
> i used paulca-phone\_codes plugin for country code.and it works.  
> \<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix)%\>  
> what i want to know is how to apply css class for this.when i tried like  
> below it doesnot work  
> \<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix),  
> {:class =\> “mystyle” }%\>
> 
> Any helps

try

\<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix),  
:style =\> "class=‘MyStyle’ %\>

You can even substitute all of the properties separated by semicolons  
(😉 within the :style =\> “” parameter.

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 10, 2009, 6:40pm UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/3 "2009-08-10T18:40:22Z")

</div>

Ahad A. wrote:

> Newb N. wrote:
> 
> > Hi…  
> > i used paulca-phone\_codes plugin for country code.and it works.  
> > \<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix)%\>  
> > what i want to know is how to apply css class for this.when i tried like  
> > below it doesnot work  
> > \<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix),  
> > {:class =\> “mystyle” }%\>
> > 
> > Any helps
> 
> try
> 
> \<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix),  
> :style =\> "class=‘MyStyle’ %\>
> 
> You can even substitute all of the properties separated by semicolons  
> (😉 within the :style =\> “” parameter.

mine why didnt work ?

\<%= post.body, :style =\> “class=‘body\_text’” %\>

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 10, 2009, 6:52pm UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/4 "2009-08-10T18:52:04Z")

</div>

\<%= post.body, :class=\> “body\_text” %\>

On Aug 10, 11:40 am, Philip G. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 10, 2009, 7:02pm UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/5 "2009-08-10T19:02:55Z")

</div>

John Y. wrote:

> \<%= post.body, :class=\> “body\_text” %\>
> 
> On Aug 10, 11:40ï¿½am, Philip G. \<rails-mailing-l…@andreas-

I have been tried this but dint work 😕

error: SyntaxError in Posts#show

compile error  
/Users/webstic/Sites/weblog2/app/views/posts/_post.html.erb:6: syntax  
error, unexpected tASSOC, expecting tCOLON2 or ‘[’ or ‘.’  
…r.concat(( post.body, :class=\> “body\_text” ).to\_s); @output_…  
^

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 10, 2009, 9:48pm UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/6 "2009-08-10T21:48:25Z")

</div>

Philip G. wrote:

> John Y. wrote:
> 
> > \<%= post.body, :class=\> “body\_text” %\>
> > 
> > On Aug 10, 11:40ï¿½am, Philip G. \<rails-mailing-l…@andreas-
> 
> I have been tried this but dint work 😕
> 
> error: SyntaxError in Posts#show

Remove the comma.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 10, 2009, 10:46pm UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/7 "2009-08-10T22:46:14Z")

</div>

On Jun 23, 7:10 am, Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi…  
> i used paulca-phone\_codes plugin for country code.and it works.  
> \<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix)%\>  
> what i want to know is how to apply css class for this.when i tried like  
> below it doesnot work  
> \<%= f.select :country\_code, PhoneCode.options\_for\_select(:prefix),  
> {:class =\> “mystyle” }%\>

Because select takes two hashes of options. The first is for options  
for select itself, the second is for html options. You’re sticking  
your html options in the first hash.

Fred

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 11, 2009, 9:52am UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/8 "2009-08-11T09:52:49Z")

</div>

Marnen Laibow-Koser wrote:

> Philip G. wrote:
> 
> > John Y. wrote:
> > 
> > > \<%= post.body, :class=\> “body\_text” %\>
> > > 
> > > On Aug 10, 11:40ï¿½am, Philip G. \<rails-mailing-l…@andreas-
> > 
> > I have been tried this but dint work 😕
> > 
> > error: SyntaxError in Posts#show
> 
> Remove the comma.
> 
> ## Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

when i remove the comma im getting this:

ArgumentError in Posts#show

Showing app/views/posts/\_post.html.erb where line #6 raised:

wrong number of arguments (1 for 0)

6: \<%= post.body :class =\> “body\_text” %\>

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [August 11, 2009, 5:31pm UTC](https://www.ruby-forum.com/t/how-to-specify-css/170823/9 "2009-08-11T17:31:52Z")

</div>

Philip G. wrote:

> Marnen Laibow-Koser wrote:
> 
> > Philip G. wrote:
> > 
> > > John Y. wrote:
> > > 
> > > > \<%= post.body, :class=\> “body\_text” %\>
> > > > 
> > > > On Aug 10, 11:40ï¿½am, Philip G. \<rails-mailing-l…@andreas-
> > > 
> > > I have been tried this but dint work 😕
> > > 
> > > error: SyntaxError in Posts#show
> > 
> > Remove the comma.
> > 
> > ## Best,
> > 
> > Marnen Laibow-Koser  
> > [http://www.marnen.org](http://www.marnen.org)  
> > removed\_email\_address@domain.invalid
> 
> when i remove the comma im getting this:

Yeah, sorry, that was a mistake on my part. You will probably have to  
wrap post.body in a div or span to specify the appropriate class.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
