Created
January 9, 2017 11:18
-
-
Save maxehmookau/5d97275c19b77e7f447bdd6bc6f8e7e8 to your computer and use it in GitHub Desktop.
Refactoring using Sandi Metz 99 bottles examples for Rails helper
This file contains hidden or 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 PlaylistCommentsHelper | |
def pinning_link(comment) | |
if comment.pinned? | |
unpin_link(comment) | |
else | |
pin_link(comment) | |
end | |
end | |
def unpin_link(comment) | |
link_to 'Unpin', playlist_playlist_comment_path(playlist_id: comment.playlist.id, id: comment.id, playlist_comment: { pinned: false }), remote: true, method: :patch | |
end | |
def pin_link | |
link_to 'Pin', playlist_playlist_comment_path(playlist_id: comment.playlist.id, id: comment.id, playlist_comment: { pinned: true }), remote: true, method: :patch | |
end | |
end |
This file contains hidden or 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 PlaylistCommentsHelper | |
def pinning_link(comment) | |
link_to(pinning_text_label(comment), playlist_playlist_comment_path(pinning_params(comment, pinning_value(comment))), pinning_http_params) | |
end | |
private | |
def pinning_params(comment, will_pin = true) | |
{ playlist_id: comment.playlist.id, id: comment.id, playlist_comment: { pinned: will_pin } } | |
end | |
def pinning_http_params | |
{ remote: true, method: :patch } | |
end | |
def pinning_text_label(comment) | |
comment.pinned? ? 'Unpin' : 'Pin' | |
end | |
def pinning_value(comment) | |
comment.pinned? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment