Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution Helper Method Written Incorrectly - Error during Server Usage #12

Closed
byojelly opened this issue Mar 7, 2018 · 1 comment
Closed
Labels

Comments

@byojelly
Copy link

byojelly commented Mar 7, 2018

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

drakeltheryuujin pushed a commit that referenced this issue Oct 3, 2019
@drakeltheryuujin
Copy link

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. 💙

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@drakeltheryuujin @byojelly and others