Forum: Ruby on Rails Concatenate 2 form fields together.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
536253930b065b5a5e8ff9b204c85001?d=identicon&s=25 Sean McGilvray (Guest)
on 2009-01-30 01:23
(Received via mailing list)
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
7e35ecb8cb04c4c15cf0ad1a0edf113d?d=identicon&s=25 anton effendi (Guest)
on 2009-01-30 04:01
(Received via mailing list)
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 = @first_name + " " + @last_name

in controller

def save
   user =
   user.first_name = params[:first_name]
   user.last_name = params[:last_name]

*way no 2*
For example model user, controller costumer
in controller

 def save
   user = = params[:first_name] + " " + params[:last_name]

I hope it will help you..
Thank you

On Fri, Jan 30, 2009 at 7:22 AM, Sean McGilvray

> Thank you,
>  Sean McGilvray
> >

Wu You Duan
536253930b065b5a5e8ff9b204c85001?d=identicon&s=25 Sean McGilvray (Guest)
on 2009-01-30 18:00
(Received via mailing list)
This is exactly what I was looking for.

Thank you,

Sean McGilvray & Sarena Byers
Identity Theft Specialist
Pre-Paid Legal Service's, Inc. NYSE:PPD
Phone:  760-486-1019
This topic is locked and can not be replied to.