0

Having a similar issue to this guy: Rails 4 with has_scope: fails silently

But his answer didn't help my situation. I'm using the has_scope gem with the following code:

#model
class Inbox < ActiveRecord::Base
  has_paper_trail
  has_many :requests
  belongs_to :match_rule
  scope :by_person, -> person { where(Request.where(inbox_id: params[:id]).person[:first_name] => person) }
end

#controller
class InboxesController < ApplicationController
  before_action :authorize
  before_action :set_inbox, only: [:show, :edit, :update, :destroy]
  before_filter :set_paper_trail_whodunnit
  has_scope :by_person

def show
  @requests = apply_scopes(Request.where(inbox_id: params[:id]).paginate(:page => params[:page], :per_page => 20))
end

private
  def set_inbox
    @inbox = Inbox.find(params[:id])
  end

Then using the url http://localhost:3000/inboxes/3?by_person=Meghan I get this error

undefined method `by_person' for #<Request::ActiveRecord_Relation:0x007fadf72a3148>

for this line

@requests = apply_scopes(Request.where(inbox_id: params[:id]).paginate(:page => params[:page], :per_page => 20))

Once I get it working with first name I'm going to move on to all other things to filter by. I appreciate any help or guidance in this situation!

Community
  • 1
  • 1
Evan Lemmons
  • 807
  • 3
  • 11
  • 27
  • Not familiar with that gem, but perhaps because Request doesn't have a by_person scope (Inbox does) – Frederick Cheung Jun 15 '16 at 21:15
  • Good call I added it to the Request model and controller and now it's throwing this error "undefined local variable or method `params' for #" but that's odd because in the same error is saying the params are as follows: "Request Parameters: {"by_person"=>"Jesse", "id"=>"2"}" what the heck? – Evan Lemmons Jun 16 '16 at 13:02

0 Answers0