Skip to content

Commit

Permalink
Form helpers accepts method as string
Browse files Browse the repository at this point in the history
  • Loading branch information
porras committed Nov 16, 2007
1 parent 400715f commit 6a839c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/form_helpers.rb
Expand Up @@ -17,7 +17,7 @@ def live_validations_for(object_name, method)
private

def live_validation(object_name, method)
if validations = self.instance_variable_get("@#{object_name.to_s}").class.live_validations[method] rescue false
if validations = self.instance_variable_get("@#{object_name.to_s}").class.live_validations[method.to_sym] rescue false
field_name = "#{object_name}_#{method}"
initialize_validator(field_name) +
validations.map do |type, configuration|
Expand Down
13 changes: 13 additions & 0 deletions test/form_helpers_test.rb
Expand Up @@ -18,6 +18,11 @@ def without_live
render :inline => "<% form_for(:resource, :url => resources_path) do |f| %><%= f.text_field :name, :live => false %><% end %>"
end

def with_string
@resource = Resource.new
render :inline => "<% form_for(:resource, :url => resources_path) do |f| %><%= f.text_field 'name' %><% end %>"
end

def name
@resource = Resource.new
render_form(:text, :name)
Expand Down Expand Up @@ -68,6 +73,14 @@ def test_without_live
check_form_item :type => 'text', :name => 'name'
end

def test_with_string
Resource.class_eval do
validates_presence_of :name
end
get :with_string
check_form_item :type => 'text', :name => 'name', :script => "var resource_name = new LiveValidation('resource_name');resource_name.add(Validate.Presence, {validMessage: \"\"})"
end

def test_presence
Resource.class_eval do
validates_presence_of :name
Expand Down

0 comments on commit 6a839c0

Please sign in to comment.