# Newbie on rails, need some help :D

**URL:** <https://www.ruby-forum.com/t/newbie-on-rails-need-some-help-d/190623>\
**Category:** Rails\
**Created:** [June 24, 2010, 3:57am UTC](https://www.ruby-forum.com/t/newbie-on-rails-need-some-help-d/190623 "2010-06-24T03:57:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbieonrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/58956e/32.png) [@newbieonrails](https://www.ruby-forum.com/u/newbieonrails)\
**Post date:** [June 24, 2010, 3:57am UTC](https://www.ruby-forum.com/t/newbie-on-rails-need-some-help-d/190623/1 "2010-06-24T03:57:21Z")

</div>

Hello, thanks for reading.

I used scaffolding to set my pages up, and I’ve been editing them to get  
the effect that I want, but I’m running into a few problems.

The first problem:

I have 2 drop down menus, with pre-determined choices, let’s say, “Ruby,  
Python, Java” are in the first drop down, and “Is awesome!, Sucks, etc.”  
are in the second. I then want to concatenate them with a space in  
between, and have that as the input into my database. Currently I have:  
\<%= f.select(:part1, List::NAME) %\>  
\<%= f.select(:part2, List::TYPE) %\>

Where NAME is the first list, and TYPE is the second, they’re defined in  
the list model. The drop down lists work, but I have no idea how to go  
about concatenating “part1” and “part2”, and nothing that I’ve tried  
works.

Second problem:

I want another drop down list, except that I want the choices to be from  
another table in the database. In other words, I have a table called  
users, which just has two fields: id and name. I want every user name to  
come up in this list. The name itself is also what I want to be saved to  
the database for that entry.

I’ve been programming for a while, and just started picking up Ruby a  
few months ago, and I completely love it. This is my first time working  
with web apps, and it’s been pretty challenging so far, and I’m hoping  
that I can get the hang of it soon. Thanks anyone for the input!

---

<div class="post-metadata">

**Author:** ![newbieonrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/58956e/32.png) [@newbieonrails](https://www.ruby-forum.com/u/newbieonrails)\
**Post date:** [June 24, 2010, 11:04am UTC](https://www.ruby-forum.com/t/newbie-on-rails-need-some-help-d/190623/2 "2010-06-24T11:04:34Z")

</div>

Newbie Onrails wrote:

> Hello, thanks for reading.
> 
> I used scaffolding to set my pages up, and I’ve been editing them to get  
> the effect that I want, but I’m running into a few problems.
> 
> The first problem:
> 
> I have 2 drop down menus, with pre-determined choices, let’s say, “Ruby,  
> Python, Java” are in the first drop down, and “Is awesome!, Sucks, etc.”  
> are in the second. I then want to concatenate them with a space in  
> between, and have that as the input into my database. Currently I have:  
> \<%= f.select(:part1, List::NAME) %\>  
> \<%= f.select(:part2, List::TYPE) %\>

Try  
\<%= f.select(:part1, {List::NAME, List::TYPE})

> Where NAME is the first list, and TYPE is the second, they’re defined in  
> the list model. The drop down lists work, but I have no idea how to go  
> about concatenating “part1” and “part2”, and nothing that I’ve tried  
> works.
> 
> Second problem:
> 
> I want another drop down list, except that I want the choices to be from  
> another table in the database. In other words, I have a table called  
> users, which just has two fields: id and name. I want every user name to  
> come up in this list. The name itself is also what I want to be saved to  
> the database for that entry.

\<%= collection\_select(:post, :user\_id, User.all, :id, :name) %\>

> I’ve been programming for a while, and just started picking up Ruby a  
> few months ago, and I completely love it. This is my first time working  
> with web apps, and it’s been pretty challenging so far, and I’m hoping  
> that I can get the hang of it soon. Thanks anyone for the input!

---

<div class="post-metadata">

**Author:** ![newbieonrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/58956e/32.png) [@newbieonrails](https://www.ruby-forum.com/u/newbieonrails)\
**Post date:** [June 24, 2010, 11:57pm UTC](https://www.ruby-forum.com/t/newbie-on-rails-need-some-help-d/190623/3 "2010-06-24T23:57:46Z")

</div>

Bohdan P. wrote:

> Try  
> \<%= f.select(:part1, {List::NAME, List::TYPE})

> \<%= collection\_select(:post, :user\_id, User.all, :id, :name) %\>

Thanks, neither of these exactly worked the way I wanted them, but it  
did help me with googling what I was looking for.

For the first one, I just kept the same code, but added in the  
controller

params[:list][:full] = params[:list][:part1] + " " +  
params[:list][:part2]  
right before  
@list = List.new(params[:list])

in the create method.

All of the creating stuff works perfectly now, but I’m having trouble  
with edit.

The drop down Name list is already picking the right name, which is  
good, but the other one isn’t.

Right now, the code is:

\<%= f.select(:part1,List::NAME,{}, {:size=\>5}) %\>  
\<%= f.select(:part2,List::TYPE,{}, {:size=\>5}) %\>

Each select has 5 options, so I opted to just use a select field instead  
of a drop down. I tried adding :selected=\>“Ruby” to the first one, but  
it didn’t do anything. I believe that the current values which should be  
defaulted can be found by full.split(" ")[0] and [1], but not really  
sure how to implement that here.

Thanks again for the response =) I think I’m starting to get a better  
feel for this.
