# Concatenate 2 form fields together

**URL:** <https://www.ruby-forum.com/t/concatenate-2-form-fields-together/158985>\
**Category:** Rails\
**Created:** [January 30, 2009, 1:23am UTC](https://www.ruby-forum.com/t/concatenate-2-form-fields-together/158985 "2009-01-30T01:23:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_McGilvray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Sean\_McGilvray](https://www.ruby-forum.com/u/Sean_McGilvray)\
**Post date:** [January 30, 2009, 1:23am UTC](https://www.ruby-forum.com/t/concatenate-2-form-fields-together/158985/1 "2009-01-30T01:23:18Z")

</div>

I am a newbie at RoR so thank you for your patients.

I have a form with the following fields:

1. first\_name
2. last\_name

I want to take them and make them into one variable “name” and submit  
that to my table field named “name”. Can anyone help?

Thank you,

Sean McGilvray

---

<div class="post-metadata">

**Author:** ![Sean\_McGilvray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Sean\_McGilvray](https://www.ruby-forum.com/u/Sean_McGilvray)\
**Post date:** [January 30, 2009, 4:01am UTC](https://www.ruby-forum.com/t/concatenate-2-form-fields-together/158985/2 "2009-01-30T04:01:04Z")

</div>

Haii  
For this case… a lot of way…

1. make name in model → this is the best way
2. make name in controller → this is good way

_way no 1_  
in model

attr\_accessor :first\_name  
attr\_accessor :last\_name

def before\_save  
self.name = @first\_name + " " + @last\_name  
end

in controller

def save  
user = User.new()  
user.first\_name = params[:first\_name]  
user.last\_name = params[:last\_name]  
user.save  
end

_way no 2_  
For example model user, controller costumer  
in controller

def save  
user = User.new  
user.name = params[:first\_name] + " " + params[:last\_name]  
user.save  
end

I hope it will help you…  
Thank you

On Fri, Jan 30, 2009 at 7:22 AM, Sean McGilvray  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> Thank you,
> 
> Sean McGilvray
> 
> >

–  
Wu You Duan

---

<div class="post-metadata">

**Author:** ![Sean\_McGilvray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Sean\_McGilvray](https://www.ruby-forum.com/u/Sean_McGilvray)\
**Post date:** [January 30, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/concatenate-2-form-fields-together/158985/3 "2009-01-30T18:00:57Z")

</div>

This is exactly what I was looking for.

Thank you,

Sean McGilvray & Sarena Byers  
Director  
Identity Theft Specialist  
Pre-Paid Legal Service’s, Inc. NYSE:PPD  
Phone: 760-486-1019  
removed\_email\_address@domain.invalid  
[http://www.transferhome.net](http://www.transferhome.net)
