Skip to content

Commit

Permalink
trim leading and trailing spaces: suggested by @diwash007
Browse files Browse the repository at this point in the history
  • Loading branch information
Bishwas-py committed Aug 13, 2022
1 parent 600a8b2 commit 687a460
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/post.rb
Expand Up @@ -20,6 +20,7 @@ class Post < ApplicationRecord

default_scope { order(created_at: :desc) }

# trim leading and trailing spaces: suggested by @diwash007
def content_emptiness
pure_text = Nokogiri::HTML(body).
xpath('//text()').map(&:text).join('').
Expand Down
1 change: 1 addition & 0 deletions app/models/quick_tweet.rb
Expand Up @@ -15,6 +15,7 @@ class QuickTweet < ApplicationRecord
has_one_attached :image, dependent: :destroy
has_many :bookmarks, as: :bookmarkable, dependent: :destroy

# trim leading and trailing spaces: suggested by @diwash007
def content_emptiness
pure_text = Nokogiri::HTML(content).
xpath('//text()').map(&:text).join('').
Expand Down

5 comments on commit 687a460

@yshmarov
Copy link
Contributor

@yshmarov yshmarov commented on 687a460 Aug 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

687a460#diff-fd0046e2ea37f7ce3e91c417c57233c4b71a3324c477b5070196305ba363835cR38

why not something simpler like post.body.presence.truncate(300)?

@Bishwas-py
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will is check if the content is all white space?

@Bishwas-py
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

687a460#diff-fd0046e2ea37f7ce3e91c417c57233c4b71a3324c477b5070196305ba363835cR38

why not something simpler like post.body.presence.truncate(300)?

Content could have a <p> tag on it with a lot of white spaces, which is considered empty by us humans, so will this fix that issue?

@yshmarov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh now I get what you are trying to achieve. never mind my previous comment. sorry for the confusion.

@Bishwas-py
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem sir. Thanks for the help. @yshmarov

Please sign in to comment.