Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upstory: check for duplicate URL on blur #413
Conversation
pushcx
requested changes
Oct 5, 2017
Thank you, @talklittle, for picking up one of my biggest pet peeve issues.
The code can be extracted a little differently to avoid a dependency, so I left some comments. Thanks!
app/assets/javascripts/application.js.erb
| checkStoryDuplicate: function(form) { | ||
| var params = $(form).serializeArray(); | ||
| $.post("/stories/check_url_dupe", params, function(data) { | ||
| var da = $.parseHTML(data); |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pushcx
Oct 5, 2017
Member
I appreciate you being consistent with the other functions, but I don't want identifiers like data and da that don't carry any meaning. There's also no need for .parseHTML if the js isn't going to do anything with the DOM, so just .html it right into place.
pushcx
Oct 5, 2017
Member
I appreciate you being consistent with the other functions, but I don't want identifiers like data and da that don't carry any meaning. There's also no need for .parseHTML if the js isn't going to do anything with the DOM, so just .html it right into place.
app/controllers/stories_controller.rb
| @story.check_url | ||
| # ignore other types of errors (e.g., invalid URL format) | ||
| if @story.already_posted_story.blank? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pushcx
Oct 5, 2017
Member
Instead of extracting all of check_url from validate, extract just the part that sets already_posted_story and maybe adds the error about it being submitted recently. Leave the regexp that checks format and adds that error.
I don't want this piece of code to have to know about all the other possible errors on URL and be maintained in sync with the model.
pushcx
Oct 5, 2017
Member
Instead of extracting all of check_url from validate, extract just the part that sets already_posted_story and maybe adds the error about it being submitted recently. Leave the regexp that checks format and adds that error.
I don't want this piece of code to have to know about all the other possible errors on URL and be maintained in sync with the model.
app/views/stories/_formerrors.html.erb
| @@ -0,0 +1,29 @@ | ||
| <div class="form_errors_header"> |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
talklittle
added some commits
Oct 5, 2017
pushcx
merged commit f0a2065
into
lobsters:master
Oct 6, 2017
1 check passed
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
pushcx
Oct 6, 2017
Member
Great to have this. It might be nice to use slideDown or something to make this a little less jarring, but I'd rather merge this now than wait.
|
Great to have this. It might be nice to use |
talklittle commentedOct 5, 2017
fixes #149