This project is archived and is in readonly mode.
humanize and human_name don't separate words
-
jack dempsey (jackdempsey)
+1 I don't feel strongly on how it should be fixed, but I do think it needs an update.
-
Justin French
- Assigned user set to Michael Koziarski
I've attached a patch which changes human_name to use titleize instead of humanize at Koz's request, and assigned it to him. Also added some test coverage, because there wasn't any!
-
José Valim
I don't know if this is appropriate because it would make human_name behave differently from human_attribute_name. And I also think that "Post comment" is a better result (more human readable) than "Post Comment".
If we cannot make humanize work properly in such cases ("PostComment" becomes "Post comment"), I would call underscore first and then humanize, which would output the right result.
-
Justin French
I'll gladly support any patch that is better than "Postcomment", which is utterly broken.
Post Comment Post comment post comment
Anything other than Postcomment!
So here's a patchfile that uses self.name.underscore.humanize, which as José pointed out, is aligned closer to what human_attribute_name does, and humanize expects underscores things anyway. Win win!
-
Niels Ganser
+1 for Justin's patch. Applies nicely and does exactly what I'd expect from human_name.
-
Michael Koziarski
This doesn't apply cleanly at present, can you rebase it and reupload?
Also the comments don't match the implementation?
-
Justin French
Ok, have rebased and corrected the comments (thanks for catching that), new file attached.
-
Francesc Esplugas
+1 for this patch as it's what I expect from this method.
-
Francesc Esplugas
Justin French last patch didn't merged with Rails Edge, updated patch.
(Feel free to change commiter name and email)
-
Repository
- State changed from new to committed
(from [7d548f795d226f57278f8bdd36298c9552421053]) Changed ActiveRecord::Base.human_name to underscore the class name before it humanizes it
This gives you 'Post comment' rather than 'Postcomment' by default.
Signed-off-by: Michael Koziarski michael@koziarski.com
[#2120 humanize and human_name don't separate words state:committed] http://github.com/rails/rails/commit/7d548f795d226f57278f8bdd36298c... -
Justin French
Thanks Francesc, thanks Koz!
-
Francesc Esplugas
Can the latest patch be applied to 2.3.X?
-
Ryan Bigg
Automatic cleanup of spam.
