I am trying to search a user by both first and last name in my rails app and am currently getting mixed results for each method I try. Is there a way to re-write any of these methods to get my desired results?

user\_controller.rb

method #1

```
def self.search(query)
  where("first_name LIKE ? OR last_name LIKE ?", "%#{query}%", "%#{query}%") 
end

```

This works for either first or last name but not both.

Method #2

```
def self.search(keywords)
  if keywords
    where(:all, :conditions => ["concat(first_name," ",last_name) like?", "%#{keywords}%"])
  end
end

```

This doesn't return any result

Method#3

```
def self.search(search)
  if search
    select('(first_name || " " || last_name) as \'ful_name\', *')
    where ['first_name LIKE :s OR last_name LIKE :s OR ful_name LIKE :s', :s => "%#{search}"]
  else
  scoped
 end
end

```

This returns the error

> 
> SQLite3::SQLException: no such column: ful\_name: SELECT "users".\* FROM "users" WHERE (first\_name LIKE '%Spider Man' OR last\_name LIKE '%Spider Man' OR ful\_name LIKE '%Spider Man') ORDER BY created\_at DESC
> 
> 
> app/views/users/index.html.erb:5:in `\_app\_views\_users\_index\_html\_erb\_\_848623016\_40254132'
> 
> 
> 

index.html.erb

```
<% provide(:title, 'Search') %>
<h1>Search</h1>

<ul class="span4 users">
  <%= render @users %>
</ul>

```

\_user.html.erb

```
<li>
  <%= image_tag user.avatar(:medium) %>
  <h4><%= link_to user.full_name, feed_user_path(user), :class => "follow-color" %></h4>
  <% if current_user.admin? && !current_user?(user) %>
    | <%= link_to "delete", user, method: :delete,
                                  data: { confirm: "You sure?" } %>
  <% end %>
</li>

```

\_header.html.erb

```
<%= form_tag users_path, method: "get", class: "search-bar" do %>
  <%= text_field_tag :search, params[:search], placeholder: "Search" %>
<% end %>

```