Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to perform a method on a params in Rails
    primarykey
    data
    text
    <p>I want to write a method that loops through all the params to make sure they aren't all blank.</p> <p>My params are:</p> <pre><code>params[:search][:company] params[:search][:phone] params[:search][:city] params[:search][:state] params[:search][:email] </code></pre> <p>I have this method:</p> <pre><code>def all_blank_check(params) array=[] params[:search].each do |key, value| array &lt;&lt; value unless value.blank? end if array.count &lt; 1 return true else return false end end </code></pre> <p>But when I try something like <code>all_blank_check(params)</code> I get the following error:</p> <pre><code>NoMethodError (undefined method `all_blank_check' for #&lt;Class:0x108c08830&gt;): </code></pre> <p>Do I need to convert the params to an array first? Can't I perform a method on params?</p> <p>Edit - full source: <pre> def index @customers = Customer.search_search(params) end</p> <code> def self.search_search(params) search_field = [] search_values = [] array = [] test = '' if !params[:search].nil? &amp;&amp; all_blank_check(params[:search] if !params[:search].nil? &amp;&amp; !params[:search][:company].blank? search_field &lt;&lt; 'customers.company LIKE ?' search_values &lt;&lt; "%#{params[:search][:company]}%" end if !params[:search].nil? &amp;&amp; !params[:search][:city].blank? search_field &lt;&lt; 'customers.city = ?' search_values &lt;&lt; "#{params[:search][:city]}" end if !params[:search].nil? &amp;&amp; !params[:search][:phone].blank? search_field &lt;&lt; 'customers.phone_1 = ?' search_values &lt;&lt; "%#{params[:search][:phone]}%" end conditions = [search_field.join(' AND ')] + search_values Customer.where(conditions).includes(:customer_contacts).limit(10) end end def all_blank_check(params) params[:search].each do |key, value| array &lt;&lt; value unless value.blank? end if array.count &lt; 1 return false end if array.count &gt; 1 return true end end </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload