Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix incorrect html class name being generated for namespaced objects.

Broken: Namespaced::Post -> namespaced/post
Fixed:  Namespaced::Post -> namespaced_post
  • Loading branch information...
commit d33fad4873f912697a562f955c0063ebfd268567 1 parent 7b947cb
@akaspick akaspick authored committed
View
6 lib/formtastic.rb
@@ -1617,13 +1617,13 @@ def semantic_#{meth}(record_or_name_or_array, *args, &proc)
options = args.extract_options!
options[:builder] ||= @@builder
options[:html] ||= {}
-
+
class_names = options[:html][:class] ? options[:html][:class].split(" ") : []
class_names << "formtastic"
class_names << case record_or_name_or_array
when String, Symbol then record_or_name_or_array.to_s # :post => "post"
- when Array then record_or_name_or_array.last.class.to_s.underscore # [@post, @comment] # => "comment"
- else record_or_name_or_array.class.to_s.underscore # @post => "post"
+ when Array then ActionController::RecordIdentifier.singular_class_name(record_or_name_or_array.last.class) # [@post, @comment] # => "comment"
+ else ActionController::RecordIdentifier.singular_class_name(record_or_name_or_array.class) # @post => "post"
end
options[:html][:class] = class_names.join(" ")
View
6 spec/form_helper_spec.rb
@@ -40,6 +40,12 @@
output_buffer.should have_tag("form.post")
end
+ it 'adds a namespaced class to the generated form' do
+ semantic_form_for(::Namespaced::Post.new, :url => '/hello') do |builder|
+ end
+ output_buffer.should have_tag("form.namespaced_post")
+ end
+
describe 'allows :html options' do
before(:each) do
semantic_form_for(:post, ::Post.new, :url => '/hello', :html => { :id => "something-special", :class => "something-extra", :multipart => true }) do |builder|
View
6 spec/spec_helper.rb
@@ -61,6 +61,12 @@ class ::Post
def id
end
end
+ module ::Namespaced
+ class Post
+ def id
+ end
+ end
+ end
class ::Author
def to_label
end
Please sign in to comment.
Something went wrong with that request. Please try again.