Undefined method `filter' for #<Class:0x007fc0600be140>
<p>I've received help from another <a href="https://stackoverflow.com/questions/39736700/rails-4-researches-doesnt-display?noredirect=1#comment66772227_39736700">question</a> but now I have this error</p>

<pre><code>undefined method `filter' for #&lt;Class:0x007fc0600be140&gt;`
</code></pre>

<p>I am trying to filter by categories (Category were created in the console, like Category.create(name: "Ruby") and so on...)</p>

<pre><code>2.3.1 :009 &gt; Category.all
  Category Load (0.2ms)  SELECT "categories".* FROM "categories"
 =&gt; #&lt;ActiveRecord::Relation [#&lt;Category id: 1, name: "Ruby", created_at: "2016-09-26 09:03:17", updated_at: "2016-09-26 09:03:17"&gt;, #&lt;Category id: 2, name: "Rails4", created_at: "2016-09-26 09:03:25", updated_at: "2016-09-27 14:32:39"&gt;, #&lt;Category id: 3, name: "Rails5", created_at: "2016-09-26 09:03:30", updated_at: "2016-09-27 14:35:25"&gt;, #&lt;Category id: 4, name: "Heroku", created_at: "2016-09-26 09:03:35", updated_at: "2016-09-27 14:35:47"&gt;, #&lt;Category id: 5, name: "AWS-Amazon", created_at: "2016-09-26 09:03:43", updated_at: "2016-09-26 09:03:43"&gt;]&gt;
</code></pre>

<p><strong>My model tuto</strong></p>

<pre><code>class Tuto &lt; ActiveRecord::Base
  acts_as_votable
  belongs_to :user
  belongs_to :category
  validates :category_id, presence: true


  def self.search(search)
    if search
      where(["title LIKE ?","%#{search}%"]).order('created_at DESC')
    else
      all
    end
  end
#moved this method in category.rb
  #def self.filter(filter)
    #if filter
      #where(["name LIKE ?","%#{filter}%"]).order('created_at DESC')
    #else
      #all
    #end
  #end
end
</code></pre>

<p><strong>My tutos controller</strong></p>

<pre><code>class TutosController &lt; ApplicationController
  before_action :authenticate_user!, only: [:new, :create]
  before_action :set_tuto, only: [:show, :edit, :update, :destroy, :upvote]


  def index
  #binding.pry
    if params[:search].present?
      @tutos = Tuto.search(params[:search]).includes(:user, :category)
    else
      @tutos = Tuto.all.includes(:user, :category)
    end

    if params[:filter].present?
      @categories = Category.filter(params[:filter])
    else
      @categories = Category.all
    end
  end


  def show
    @tuto = Tuto.find(params[:id])
    @user = User.all
  end

  def new
    @tuto = Tuto.new
  end

  def edit
  end

  def create

    @tuto = Tuto.new(tuto_params)
    @tuto.user_id = current_user.id

    respond_to do |format|
      if @tuto.save
        flash[:success] = "Test"
        format.html { redirect_to @tuto, notice: 'Tuto was successfully created.' }
        format.json { render :show, status: :created, location: @tuto }
      else
        format.html { render :new }
        format.json { render json: @tuto.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    respond_to do |format|
      if @tuto.update(tuto_params)
        format.html { redirect_to @tuto, notice: 'Tuto was successfully updated.' }
        format.json { render :show, status: :ok, location: @tuto }
      else
        format.html { render :edit }
        format.json { render json: @tuto.errors, status: :unprocessable_entity }
      end
    end
  end


  def destroy
    @tuto.destroy
    respond_to do |format|
      format.html { redirect_to tutos_url, notice: 'Tuto was successfully destroyed.' }
      format.json { head :no_content }
    end
  end


  def upvote
    @tuto.upvote_by current_user
    redirect_to :back
  end


  private


    def set_tuto
      @tuto = Tuto.find(params[:id])
    end

    def tuto_params
      params.require(:tuto).permit(:title, :content, :id, :user_id, :category_id)
    end
end
</code></pre>

<p><strong>The view index</strong></p>

<pre><code>.container
  .row
    h1.text-gray Tutorials 
  .row.search_banner
    .col-xs-3
      =form_tag tutos_path, :method =&gt; 'get' do 
        =text_field_tag :search, params[:search],  placeholder:"Search by keywords"
        =submit_tag "Search", class:'btn btn-xs btn-default btn-search'

    .col-xs-3
      =form_tag tutos_path, :method =&gt; 'get' do 
        =select_tag :filter, options_for_select(Category.all.map{|c| c.name}, params[:filter])
        =submit_tag "Search", class:"btn btn-xs btn-default btn-search"
</code></pre>

<h1>EDIT and new trouble....</h1>

<p>I've moved the <code>self_filter</code>method into my category model and it looks better even though I still can't filter by categories... When I select for exemple "heroku" everything is still here... What could be wrong?</p>

<pre><code>class Category &lt; ActiveRecord::Base
  has_many :tutos

  def self.filter(filter)
    if filter
      where(["name LIKE ?","%#{filter}%"]).order('created_at DESC')
    else
      all
    end
  end
end
</code></pre>