title: Trying to search by first_name and last_name
body: <p>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?</p>
  <p>user_controller.rb</p>
  <p>method #1</p>
  <pre><code>def self.search(query)
    where(&quot;first_name LIKE ? OR last_name LIKE ?&quot;, &quot;%#{query}%&quot;, &quot;%#{query}%&quot;) 
  end
  </code></pre>
  <p>This works for either first or last name but not both.</p>
  <p>Method #2</p>
  <pre><code>def self.search(keywords)
    if keywords
      where(:all, :conditions =&gt; [&quot;concat(first_name,&quot; &quot;,last_name) like?&quot;, &quot;%#{keywords}%&quot;])
    end
  end
  </code></pre>
  <p>This doesn't return any result</p>
  <p>Method#3</p>
  <pre><code>def self.search(search)
    if search
      select('(first_name || &quot; &quot; || last_name) as \'ful_name\', *')
      where ['first_name LIKE :s OR last_name LIKE :s OR ful_name LIKE :s', :s =&gt; &quot;%#{search}&quot;]
    else
    scoped
   end
  end
  </code></pre>
  <p>This returns the error</p>
  <blockquote>
  <p>SQLite3::SQLException: no such column: ful_name: SELECT &quot;users&quot;.* FROM &quot;users&quot;  WHERE (first_name LIKE '%Spider Man' OR last_name LIKE '%Spider Man' OR ful_name LIKE '%Spider Man')  ORDER BY created_at DESC</p>
  <p>app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__848623016_40254132'</p>
  </blockquote>
  <p>index.html.erb</p>
  <pre><code>&lt;% provide(:title, 'Search') %&gt;
  &lt;h1&gt;Search&lt;/h1&gt;
  
  &lt;ul class=&quot;span4 users&quot;&gt;
    &lt;%= render @users %&gt;
  &lt;/ul&gt;
  </code></pre>
  <p>_user.html.erb</p>
  <pre><code>&lt;li&gt;
    &lt;%= image_tag user.avatar(:medium) %&gt;
    &lt;h4&gt;&lt;%= link_to user.full_name, feed_user_path(user), :class =&gt; &quot;follow-color&quot; %&gt;&lt;/h4&gt;
    &lt;% if current_user.admin? &amp;&amp; !current_user?(user) %&gt;
      | &lt;%= link_to &quot;delete&quot;, user, method: :delete,
                                    data: { confirm: &quot;You sure?&quot; } %&gt;
    &lt;% end %&gt;
  &lt;/li&gt;
  </code></pre>
  <p>_header.html.erb</p>
  <pre><code>&lt;%= form_tag users_path, method: &quot;get&quot;, class: &quot;search-bar&quot; do %&gt;
    &lt;%= text_field_tag :search, params[:search], placeholder: &quot;Search&quot; %&gt;
  &lt;% end %&gt;
  </code></pre>