Skip to content

Instantly share code, notes, and snippets.

@Sylvance
Created August 23, 2019 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sylvance/f6c5e5de1c667aebcdf23ab3dd849a97 to your computer and use it in GitHub Desktop.
Save Sylvance/f6c5e5de1c667aebcdf23ab3dd849a97 to your computer and use it in GitHub Desktop.
module AlbumConcern
private
def set_album
@album = Album.find(params[:id])
end
def filter_albums(albums)
filter = params[:filter]
return albums unless filter
Albums::AlbumFiltersQuery.call(albums, params)
end
def album_params
params.require(:album).permit(:title,
:center_id,
:description,
event_list: [],
tag_list: [],
user_group_ids: []).merge(
user_id: @current_user.id,
)
end
def search_albums(albums, query)
return albums unless query
albums.search(query)
end
def find_user_group
if album_params.key?("user_group_ids")
user_group_ids = album_params["user_group_ids"]
user_group_ids.each do |id|
if UserGroup.find_by(id: id).nil?
@album.errors.add(
:user_group, "Couldn't find UserGroup with id #{id}"
)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment