Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use model_name.human if available, otherwise use our human_name worka…

…round (#242)
  • Loading branch information...
commit a722680948344e56032202520cdd9f1400e66605 1 parent eb77723
@yabawock yabawock authored
Showing with 11 additions and 4 deletions.
  1. +1 −0  CHANGELOG
  2. +8 −4 lib/formtastic.rb
  3. +2 −0  spec/spec_helper.rb
View
1  CHANGELOG
@@ -4,6 +4,7 @@
* Changed spec_helper to support Rails 2 with Rspec od Rails 3 with Rspec 3 environments
* Changed Rakefile to initalize the correct testing framework for the enviroment
* Fixed inputs_for_nested_attributes only appending to the output buffer
+* Fixed use of model_name.human instead of model_name.human_name (rails3)
* Added railtie to perform initialization tasks after the rails git framework is available (rails3)
* Added helper to mark strings as HTML safe depending on environment, adapted from haml 2.2 solution (rails3)
* Added compatible install and form helpers (rails3)
View
12 lib/formtastic.rb
@@ -327,10 +327,14 @@ def commit_button(*args)
# ActiveRecord::Base.human_name falls back to ActiveRecord::Base.name.humanize ("Userpost")
# if there's no i18n, which is pretty crappy. In this circumstance we want to detect this
# fall back (human_name == name.humanize) and do our own thing name.underscore.humanize ("User Post")
- object_human_name = @object.class.human_name # default is UserPost => "Userpost", but i18n may do better ("User post")
- crappy_human_name = @object.class.name.humanize # UserPost => "Userpost"
- decent_human_name = @object.class.name.underscore.humanize # UserPost => "User post"
- object_name = (object_human_name == crappy_human_name) ? decent_human_name : object_human_name
+ if @object.class.respond_to?(:human)
+ object_name = @object.class.human
+ else
+ object_human_name = @object.class.human_name # default is UserPost => "Userpost", but i18n may do better ("User post")
+ crappy_human_name = @object.class.name.humanize # UserPost => "Userpost"
+ decent_human_name = @object.class.name.underscore.humanize # UserPost => "User post"
+ object_name = (object_human_name == crappy_human_name) ? decent_human_name : object_human_name
+ end
else
key = :submit
object_name = @object_name.to_s.send(@@label_str_method)
View
2  spec/spec_helper.rb
@@ -159,6 +159,7 @@ def new_author_path; "/authors/new"; end
::Author.stub!(:find).and_return([@fred, @bob])
::Author.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
::Author.stub!(:human_name).and_return('::Author')
+ ::Author.stub!(:human).and_return('::Author')
::Author.stub!(:reflect_on_validations_for).and_return([])
::Author.stub!(:reflect_on_association).and_return { |column_name| mock('reflection', :options => {}, :klass => Post, :macro => :has_many) if column_name == :posts }
::Author.stub!(:content_columns).and_return([mock('column', :name => 'login'), mock('column', :name => 'created_at')])
@@ -195,6 +196,7 @@ def new_author_path; "/authors/new"; end
::Post.stub!(:human_attribute_name).and_return { |column_name| column_name.humanize }
::Post.stub!(:human_name).and_return('Post')
+ ::Post.stub!(:human).and_return('Post')
::Post.stub!(:reflect_on_all_validations).and_return([])
::Post.stub!(:reflect_on_validations_for).and_return([])
::Post.stub!(:reflect_on_association).and_return do |column_name|
Please sign in to comment.
Something went wrong with that request. Please try again.