Substring first name from "User.select(:name, :address)". How?

I would like to get the first name from :name field below, how do I do
that
with numerous fields returned?

User.select(:name, :address).where({ id: params[:seller_id]})

You need some idea of the form of :name. Lets assume it’s a whitespace
separated string like “Brandon Q. Public”. You could simply use ruby’s
String.split. Of course if some users are royalty you could end up with
lots of users named “Sir” or “Princess”.

The issue was I was kind of stuck with having to use ‘name’ because my
PhoneGap app was calling it.

So I ended up calling a set_name method before returning the JSON.
Thanks
for your help!

def set_name
self.name = self.name.split(’ ').first
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs