You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the current solution code, when you create a new song without inserting an Artist name in the form, the Song is persisted to the database with a new artist that is a blank string "". The solution code for the Artist helper method (below), only checks if the song.artist is valid, not if it is a blank string. module ArtistsHelper def display_artist(song) if song.artist link_to song.artist.name, song.artist else link_to 'Add Artist', edit_song_path(song) end end end
This leads to user errors when testing in the server. After creating this new song without an artist, the next page (song show) will not display the expected "Add Artist" link because the instance of the song does have an artist attribute of "" . This also leads to similar errors in the index page.
I believe that the solution helper method should be changed to the following to accommodate the fix.
module ArtistsHelper
def display_artist(song)
#binding.pry
if song.artist && song.artist.name != ""#is valid
link_to song.artist.name, artist_path(song.artist)
else #if nil
link_to "Add Artist", edit_song_path(song)
end
end
end
The text was updated successfully, but these errors were encountered:
Thank you for spotting this issue and providing feedback.
We have updated the materials and believe your issue to have been resolved.
If you do not believe that this issue has been addressed, please re-open this issue. 💙
With the current solution code, when you create a new song without inserting an Artist name in the form, the Song is persisted to the database with a new artist that is a blank string "". The solution code for the Artist helper method (below), only checks if the song.artist is valid, not if it is a blank string.
module ArtistsHelper def display_artist(song) if song.artist link_to song.artist.name, song.artist else link_to 'Add Artist', edit_song_path(song) end end end
This leads to user errors when testing in the server. After creating this new song without an artist, the next page (song show) will not display the expected "Add Artist" link because the instance of the song does have an artist attribute of "" . This also leads to similar errors in the index page.
I believe that the solution helper method should be changed to the following to accommodate the fix.
module ArtistsHelper
def display_artist(song)
#binding.pry
if song.artist && song.artist.name != ""#is valid
link_to song.artist.name, artist_path(song.artist)
else #if nil
link_to "Add Artist", edit_song_path(song)
end
end
end
The text was updated successfully, but these errors were encountered: