Skip to content

Adds a format_display_using option for the number field #3821

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zhephyn
Copy link
Contributor

@zhephyn zhephyn commented Apr 30, 2025

This PR adds a format_display_using option for the number field such that instead of this:

field :amount, as: number, format_using: -> do
  if view == :index || view == :show
    number_to_currency value
  else
    value
  end
end

We can do this instead which is more cleaner and allows us to apply appropriate formatting on a value for both the index and show views at once :

field :amount, as: number, format_display_using: -> { number_to_currency value }

Solves #1902

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

end

def value(property = nil)
Copy link

Choose a reason for hiding this comment

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

Method value has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

Copy link

codeclimate bot commented Apr 30, 2025

Code Climate has analyzed commit 1d4abd0 and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1

View more on Code Climate.

@zhephyn
Copy link
Contributor Author

zhephyn commented Apr 30, 2025

@Paul-Bob . I have a working solution so far. Before i proceed with writing tests for this particular feature and solving the failed CI checks, i wanted check if this is going in the expected direction. If yes, I'll proceed to write the tests and then update the docs.

Also, i opted for implementing just the format_display_using option alone since it allows us to do formatting for both the index and show views at once, instead of implementing individual options named format_index_using and format_show_using for the index and show page respectively.
In case these had to be implemented as well, kindly let me know and I'll make the necessary changes.

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

Successfully merging this pull request may close these issues.

1 participant