# Font selector using radio button

**URL:** <https://www.ruby-forum.com/t/font-selector-using-radio-button/173472>\
**Category:** Ruby\
**Created:** [August 10, 2009, 7:09am UTC](https://www.ruby-forum.com/t/font-selector-using-radio-button/173472 "2009-08-10T07:09:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdellaringa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tdellaringa](https://www.ruby-forum.com/u/tdellaringa)\
**Post date:** [August 10, 2009, 7:09am UTC](https://www.ruby-forum.com/t/font-selector-using-radio-button/173472/1 "2009-08-10T07:09:46Z")

</div>

I have looked all around to try and find an answer to this. I have the  
Agile book and although it has lots of information, it has relatively  
little on radio buttons. I have a website in which I want users to be  
able to format their posts in relation to font and color. My goal is to  
allow them to click a radio button next to their choice of font and  
their choice of color. So far I have been unable to find anything in  
the book, on this site, or on the internet to help me out.

Here is my controller:

class PostsController \< ApplicationController

# GET /posts

# GET /posts.xml

def index  
@posts = Post.find(:all, :order =\> “created\_at DESC”)

```
  respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @posts }
end

```

end

# GET /posts/1

# GET /posts/1.xml

def show

```
respond_to do |format|
  format.html # show.html.erb
  format.xml { render :xml => @post }
end

```

end

# GET /posts/new

# GET /posts/new.xml

def new  
@post = Post.new

```
respond_to do |format|
  format.html # new.html.erb
  format.xml { render :xml => @post }
end

```

end

# POST /posts

# POST /posts.xml

def create  
@post = Post.new(params[:post])

```
respond_to do |format|
  if @post.save
    format.html { redirect_to(@post) }
    format.xml { render :xml => @post, :status => :created,

```

:location =\> @post }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @post.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

end

Here is the part of my view of the post form:

\<%= error\_messages\_for :post %\>

\<% form\_for(@post) do |f| %\>

#there is other stuff here it just isn’t important and is a little  
long.  
#here is where I want the buttons. I just have no idea how to do it.

Sorry if this is something very simple. I am new to ruby and thus don’t  
have much experience. Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![tdellaringa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tdellaringa](https://www.ruby-forum.com/u/tdellaringa)\
**Post date:** [August 10, 2009, 10:38am UTC](https://www.ruby-forum.com/t/font-selector-using-radio-button/173472/2 "2009-08-10T10:38:00Z")

</div>

In your copy of the Agile book, look at the section entitled “working  
with non-model fields” (section 22.7 or 23.7 depending on which edition  
you have). Replace text\_field\_tag with radio\_button\_tag or check\_box\_tag  
as appropriate. Then your controller can read params[:color] or  
whatever, and style the response appropriately.

You’ll find more info in the Rails API documentation under  
ActionView::Helpers::FormTagHelper - go to [http://api.rubyonrails.org/](http://api.rubyonrails.org/)

However I’m afraid your question has very little to do with Ruby (the  
programming language).

For help with Rails (the web application framework), you would be best  
advised to ask your question on a Rails mailing list or forum. There are  
some Rails users here, but this is not the primary focus of this mailing  
list.

For help with styling web pages, you could ask a CSS mailing list.

If you want the style changes to be reflected immediately when someone  
presses a button, you’ll want to use Javascript and/or a Javascript  
helper library (I prefer jQuery over Rails’ default Prototype). Again,  
there are separate mailing lists for those.

HTH,

Brian.

---

<div class="post-metadata">

**Author:** ![tdellaringa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tdellaringa](https://www.ruby-forum.com/u/tdellaringa)\
**Post date:** [August 10, 2009, 11:09am UTC](https://www.ruby-forum.com/t/font-selector-using-radio-button/173472/3 "2009-08-10T11:09:03Z")

</div>

Tom D. wrote:

> I have looked all around to try and find an answer to this. I have the  
> Agile book and although it has lots of information, it has relatively  
> little on radio buttons. I have a website in which I want users to be  
> able to format their posts in relation to font and color. My goal is to  
> allow them to click a radio button next to their choice of font and  
> their choice of color. So far I have been unable to find anything in  
> the book, on this site, or on the internet to help me out.

First, this isn’t a forum for rails questions. This is a general ruby  
programming forum. rails is a complex piece of software written in  
ruby. People who use that complex piece of software often hang out  
together and discuss various issues that they are having with the  
software. You need to locate one of those places. They are generally  
titled “Ruby on Rails” or just “Rails”.

Second, your question really has nothing to do with rails nor with ruby  
programming in general. rails software executes on “the server side”.  
A person looking at your web page is on the “client side”. In between  
the server side and the client side is a bunch of cables commonly called  
the internet. The font and color choices that you want to give your  
users can all be handled on the client side with javascript and css.  
The server side shouldn’t be bothered with such mundane details. You  
can add a simple onclick javascript function to your radio buttons that  
you can use to immediately change any css property, e.g. font size and  
colors.

I guess if you want to save the user’s choices for the next time they  
visit, you also need to set a cookie. Once again, you can do that with  
javascript. If you set a cookie with javascript, then all subsequent  
requests that the client sends to the server will include the cookie.  
Then you can have your rails app read the cookie and send back a page  
that has the font and color set according to the choices read from the  
cookie.

In any case, that is all stuff you should have learned before ever even  
attempting rails. Web programming requires a general knowledge of html,  
css, javascript, and at least one server side programming language (e.g.  
php, java, python ruby). If someone led you to believe that learning  
rails would obviate the need to learn those subjects first, they were  
sadly mistaken. You are flying blind without those subjects, and if  
any little thing goes wrong with your rails program, you have no skills  
to solve the problem.
