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

  • SEARCH
  • Home
  • 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 7546701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:16:00+00:00 2026-05-30T09:16:00+00:00

I have the following rails model: class Customer < ActiveRecord::Base attr_accessible :firstname, :lastname, :email,

  • 0

I have the following rails model:

class Customer < ActiveRecord::Base

   attr_accessible :firstname, :lastname, :email, :phonenumber, :company_id

   def name
      "#{self.lastname} #{self.firstname}"
   end

   scope :search_by_name, lambda { |q|
       (q ? where(["firstname LIKE ? or lastname LIKE ? or (firstname || ' ' || lastname) like ?", '%'+ q + '%', '%'+ q + '%','%'+ q + '%' ])  : {})
   }

end

I retrieve a JSON object of that model via ajax.
The problem is that i want to access the name attribute in my autocomplete text field (I don’t want to combine firstname and lastname in one database field).

Does somebody now how to access the name attribute in javascript or how to send the name attribute in the json object? (and which method is best)

  • 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-05-30T09:16:01+00:00Added an answer on May 30, 2026 at 9:16 am

    When your controller renders the json you can specify what to send. By overriding the default json sent you could specify the name.

    Something along the lines of:

    render :json => { :customer => { :name => @customer.name, :email => @customer.email } }
    

    Or you could look into using a json builder like https://github.com/rails/jbuilder if you intend to have more complex json being sent.

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

Sidebar

Related Questions

I have the following model and methods: class UserPrice < ActiveRecord::Base attr_accessible :price, :purchase_date,
I have the following Rails model: class CreateFoo < ActiveRecord::Migration def self.up create_table :foo
I have the following model, Purchase, on my Rails app: class Purchase < ActiveRecord::Base
I have a the following rails models: class Release < ActiveRecord::Base has_many :release_questionnaires, :dependent
I have a ActiveRecord Car model: class Car < ActiveRecord::Base def check_value puts self.load_size
I have the following code for my user model: class User < ActiveRecord::Base has_secure_password
I have the following model: class Advisor < ActiveRecord::Base belongs_to :course end class Course
I have a simple model: class User < ActiveRecord::Base has_and_belongs_to_many :roles end class Role
I have the following models: class Survey < ActiveRecord::Base set_primary_key :survey_id # I'm using
I have a model class as shown below: class Product < ActiveRecord::Base belongs_to :user;

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.