# Concatenate first\_name & last\_name in select

**URL:** <https://www.ruby-forum.com/t/concatenate-first-name-last-name-in-select/121142>\
**Category:** Rails\
**Created:** [November 24, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/concatenate-first-name-last-name-in-select/121142 "2007-11-24T15:28:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [November 24, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/concatenate-first-name-last-name-in-select/121142/1 "2007-11-24T15:28:14Z")

</div>

Hey,

I want to populate a select drop down form helper with FIRST NAME + LAST  
NAME.

However, these are both in separate columns in the DB - how can I join  
them together?

I can manage to populate it with just the first names, like this…

===VIEW====

\<%= select(:first\_name, :id, @guests) %\>

===CONTROLLER===

```
@guests = Guest.find(:all, :conditions => ["group_id = ? and

```

event\_id = ?", params[:id], params[:event]]).map { |u| [u.first\_name, u.id]}

Any ideas?

Thanks

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [November 24, 2007, 5:58pm UTC](https://www.ruby-forum.com/t/concatenate-first-name-last-name-in-select/121142/2 "2007-11-24T17:58:11Z")

</div>

On Nov 24, 2007, at 9:28 AM, Scott H. wrote:

> Any ideas?
> 
> Thanks

I’d suggest getting that stuff out of the controller and into the model:

==Model==

class Guest  
def self.choices\_for\_name\_by\_group\_and\_event(group\_id, event\_id)  
find(:all, :conditions =\> [‘group\_id = ? AND event\_id = ?’,  
group\_id, event\_id]).  
map {|u| [u.name, u.id] }  
end  
def name  
“#{first\_name} #{last\_name}”  
end  
end

==Controller==

@guests = Guest.choices\_for\_name\_by\_group\_and\_event(params[:group\_id],  
params[:event\_id])

==View==

```
 <%= select(:object, :method, @guests) %>

```

(your select call doesn’t make sense unless you have a variable  
@first\_name)

That should help you make some sense of it. The biggest help is  
having the logic in the model.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
