I’m building a rails app where users can search through “Playlists”, which is an object containing a title, image, and tracks.
I’ve defined a search method in the Playlist model that takes one parameter: “query”. It doesn’t seem to recognize when a parameters are given, returning “expected 1 parameter, 0 given” error.
Playlist model (playlist.rb)
class Playlist < ApplicationRecord
...
def self.search_all(query)
if query
self.where("title LIKE ?", "%#{search_all}%")
else
Playlist.all
end
end
end
Playlist controller (playlists_controller.rb)
class PlaylistsController < ApplicationController
# GET /playlists or /playlists.json
def index
search = params[:search]
if search_all
@playlists = Playlist.search_all(search)
else
@playlists = Playlist.all
end
end
...
private
# Only allow a list of trusted parameters through.
def playlist_params
params.require(:playlist).permit(:title, :image, :search_all)
end
end
How do I get my controller to “see” the parameters I’ve added?