Created
August 23, 2019 09:27
-
-
Save Sylvance/f6c5e5de1c667aebcdf23ab3dd849a97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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