# Set a select box with default value selected

**URL:** <https://www.ruby-forum.com/t/set-a-select-box-with-default-value-selected/175501>\
**Category:** Rails\
**Created:** [September 14, 2009, 10:10pm UTC](https://www.ruby-forum.com/t/set-a-select-box-with-default-value-selected/175501 "2009-09-14T22:10:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deostroll](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9c0ed/32.png) [@deostroll](https://www.ruby-forum.com/u/deostroll)\
**Post date:** [September 14, 2009, 10:10pm UTC](https://www.ruby-forum.com/t/set-a-select-box-with-default-value-selected/175501/1 "2009-09-14T22:10:00Z")

</div>

I am relating to the book & subject example mentioned in the tutorial  
mentioned here:

> **[Ruby on Rails 2.1 - Examples](http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-examples.htm)**
>
> Ruby on Rails 2 1 Examples - Subsequent chapters are based on the example taken in this chapter. In this chapter, we will create a simple but operational online library system for holding and managing the books.

There is a file that goes like show\_subjects.html.erb and it will list  
all the books for that particular subject we’ve selected.

Suppose if there were no books to show for the subject we can ideally  
show a corresponding message like “there are no books for this subject  
yet”

I’d like to rewrite that is “there are no books for this subject,  
would you like to add one?”

Lets say that the ‘would you like to add’ part is a link to the book  
create view where in we add a book. How do I load that page to have  
its select box show the subject tht had no books (from where I was  
initially at)…?

–deostroll

---

<div class="post-metadata">

**Author:** ![deostroll](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9c0ed/32.png) [@deostroll](https://www.ruby-forum.com/u/deostroll)\
**Post date:** [September 15, 2009, 12:04am UTC](https://www.ruby-forum.com/t/set-a-select-box-with-default-value-selected/175501/2 "2009-09-15T00:04:46Z")

</div>

Something like…

# views/subject/show

\<%= link\_to ‘Would you like to add one?’, new\_book\_path, {:subj =\>  
@subject} %\>

# controllers/books\_controller

def new  
@book = Book.new  
@book.subject = params[:subj]  
# etc…  
end

HTH,

-Roy

---

<div class="post-metadata">

**Author:** ![deostroll](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9c0ed/32.png) [@deostroll](https://www.ruby-forum.com/u/deostroll)\
**Post date:** [September 21, 2009, 10:00pm UTC](https://www.ruby-forum.com/t/set-a-select-box-with-default-value-selected/175501/3 "2009-09-21T22:00:35Z")

</div>

How do I re-write the new.html.erb?
