Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8660111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:10:30+00:00 2026-06-12T16:10:30+00:00

I have 3 columns in my table projects. first_name, last_name, and fullname. <%= f.hidden_field

  • 0

I have 3 columns in my table projects. first_name, last_name, and fullname.

<%= f.hidden_field :first_name, :value => current_user.firstname %>
<%= f.hidden_field :last_name, :value => current_user.lastname %>

At the moment when the user saves a project, the first name and last name of user get saved into separate columns. I am now wanting for both the first name and last name to get saved to a column full name, so I can search on them later.

So if the name was

first_name = "Joe"
last_name = "Bloggs"

How would I get

fullname =  "Joe Bloggs"

I tried this, but it doesn’t work.

<%=f.hidden_field :fullname, :value => :first_name + :last_name %>

Can someone point me in the right direction? I’m new to rails so please remember this when trying to help. Thanks.

UPDATE

Now I have added this to my project model:

def set_fullname
    fullname = first_name + last_name
  end

and I now call this in my view:

<%= f.hidden_field :first_name, :value => current_user.firstname %>
<%= f.hidden_field :last_name, :value => current_user.lastname %>
<%= f.hidden_field :fullname, :value => @project.fullname %>

When I hit submit, and I check the logs the first and last names get saved to the table as usual, but the full name goes in blank. Can anyone see what the problem is?

UPDATE2

View:

<%= f.hidden_field :first_name, :value => current_user.firstname %>
<%= f.hidden_field :last_name, :value => current_user.lastname %>
<%= f.hidden_field :fullname, :value => @project.set_fullname %>

Project Model:

def set_fullname
    fullname = first_name + last_name
  end

When I try to access the page I get this error.

undefined method `+' for nil:NilClass
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:10:32+00:00Added an answer on June 12, 2026 at 4:10 pm

    Ruby code in your view is executed when the form is loaded, by that time there is no content in the form (if you create a new record). It would make sense to write similar code in javascript an map it to onchange event first_name and last_name text field.

    Or you can do it on server side in your model, e.g:

    class Person
    
      before :save, :set_fullname
    
      def set_fullname
        fullname = "#{first_name} #{last_name}"
      end
    end
    

    before :save is executed each time when you’re update your model

    Anyway much cleaner solution would be to adjust your search query, this way you just duplicate information in your database.

    While searching try something like this:

    "first_name LIKE ? or last_name LIKE ? or concat(last_name, ', ', first_name) LIKE ?"
    

    this SQL code might be database dependent, if you’re using MySQL it’s probably ok

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database 'Sample' with a table 'User' with columns 'FirstName', 'LastName', 'Category'.
I Have a DataBase in my project With Table named 'ProcessData' and columns named
The table columns have the data type BLOB and CLOB. What are the corresponding
I have temp table #xml that have 2 columns: CREATE TABLE #xml ( id
I have three columns in mysql table: tax_id, company_name, store_name. I need that tax_id
I have two columns in my table and the rows are created dynamically. <table
I have 2 Columns in a table. Activities and Average % of Time, For
I have 2 columns in a table and I would like to roughly report
I have 6 columns in a table. I have a select query which selects
I have two columns in a table that are populated with integer values. For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.