Search code examples
ruby-on-railserror-handlingincludeactioncontroller

Rails "The parameter passed to #in? must respond to #include?"


as a follow up of another question here, i have added the following code to my records_controller.rb

if params[:order].in? %s[year artist title]
  # adds ORDER to the scope
  @records.merge!( Record.order("? DESC", params[:order]) )
end

but then i got an error:

"The parameter passed to #in? must respond to #include?"

what does this mean? What do i need to change?


Solution

  • From the documentation:

    in?(another_object) public

    Returns true if this object is included in the argument.

    Argument must be any object which responds to #include?

    include? responds to an array of object which should be in format %w[year artist title] but not to a symbol as you have written %s[year artist title]

    %w[year artist title] # => ["year", "artist", "title"] can be used for include? and in?
    %i[year artist title] # => [:year, :artist, :title] can be used for include? and in?
    
    %s[year artist title] # => :"year artist title" which is a symbol that can not be used for include? or in?