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

Code-only improvement: avoiding reimplementing the built in truncate method #1420

Open
trichoplax opened this issue Sep 27, 2024 · 0 comments
Labels
area: ruby Changes to server-side code complexity: easy Issues that should take limited effort to resolve/fix/build. hacktoberfest This repo participates in Hacktoberfest 2023. For suitable issues and Hacktoberfest-PRs meta: good first issue Good for newcomers meta: help wanted Extra attention is needed priority: low type: change request New feature or request

Comments

@trichoplax
Copy link
Contributor

Describe the bug
In the file app/views/users/_activity_items.html.erb there are 4 occurrences of truncating a string using a line of code, which has identical behaviour to the built in truncate method:

  • line 22: <%= i.body_plain[0..300] + ((i.body_plain.length > 300) ? "..." : "") %><br>
  • line 34: <%= i.content[0..300] + ((i.content.length > 300) ? "..." : "") %><br>
  • line 73: <%= i.body[0..300] + ((i.body.length > 300) ? "..." : "") %>
  • line 88: <%= i.reason[0..300] + ((i.reason.length > 300) ? "..." : "") %><br>

For example usage of the truncate method, see app/views/posts/show.html.erb line 1.

We could avoid this duplicated code by replacing these 4 occurrences with calls to truncate.

@ArtOfCode- ArtOfCode- added area: ruby Changes to server-side code meta: good first issue Good for newcomers meta: help wanted Extra attention is needed type: change request New feature or request priority: low complexity: easy Issues that should take limited effort to resolve/fix/build. hacktoberfest This repo participates in Hacktoberfest 2023. For suitable issues and Hacktoberfest-PRs labels Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ruby Changes to server-side code complexity: easy Issues that should take limited effort to resolve/fix/build. hacktoberfest This repo participates in Hacktoberfest 2023. For suitable issues and Hacktoberfest-PRs meta: good first issue Good for newcomers meta: help wanted Extra attention is needed priority: low type: change request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants