Ruby simple search form error -


as ruby-on-rails beginner, creating very simple app test search form. here everything:

person model

class person < activerecord::base  def self.search(search)  if search   all(:conditions => ['name ?', "%#{search}%"])  else    end end  end 

persons controller

class personscontroller < applicationcontroller  def index   @person = person.search(params[:search])  end end 

person#index

<h1>persons#index</h1>  <%= form_tag persons_index_path, :method => 'get' %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "search", :name => nil %> 

<% end %>

<div> <% @person.each |person| %> <p><%= person.name %><p> <% end %> </div> 

when load index , use search form, error:

wrong number of arguments (1 0)

extracted source (around line #5): 3 4 5 6 7 8

def self.search(search)  if search   all(:conditions => ['name ?', "%#{search}%"])  else    end 

no doubt making simple mistake, suggestions?

change search method to: (minified version)

def self.search(search)   search.present? ? where('name ?', "%#{search}%") : end 

or old method: (your same old structure)

def self.search(search)    if search.present?      where('name ?', "%#{search}%")    else         end end 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -