grimen / validatious-on-rails

Rails plugin that maps model validations to class names on form elements to integrate with Validatious. IMPORTANT: Project is not maintained anymore.
MIT License
346 stars 13 forks source link

`interning empty string` #6

Closed lapluviosilla closed 14 years ago

lapluviosilla commented 14 years ago

I just installed validatious-on-rails for the first time and I got a series of errors that resulted in almost every single page giving an error. Looks like a great gem, I'd love to get it working.

I get a "interning empty string" error when I try to access the new page for my person model:

new.html.haml

person.rb

class Person < ActiveRecord::Base
  has_one :account, :foreign_key => "owner_id"
  has_many :needs, :class_name => "RegistrationItem", :foreign_key => "beneficiary_id"

  validates_presence_of :first_name, :last_name
  validates_presence_of :email, :if => Proc.new { |person| !person.account.nil? }

  attr_readonly :full_name
  attr_protected :full_name

  before_validation :cache_virtual_columns

  def full_name
    [first_name, middle_name, last_name].compact.join(' ')
  end

  private
    def cache_virtual_columns
      self.full_name = full_name
    end
end

Full stack trace:

/Users/paul/Documents/Projects/msvngit/rails/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:344:in `respond_to?'
/Users/paul/Documents/Projects/msvngit/rails/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:344:in `respond_to?'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:477:in `options_require_validation?'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:463:in `method_required?'
/Users/paul/Documents/Projects/msvngit/rails/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:211:in `any?'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:460:in `each'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:460:in `any?'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:460:in `method_required?'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:85:in `input'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:256:in `inputs'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:256:in `map'
/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:256:in `inputs'
/Users/paul/Documents/Projects/msvngit/rails/app/views/people/_person.html.haml:2:in `_run_haml_app47views47people47_person46html46haml_locals_object_person'
/Users/paul/Documents/Projects/msvngit/rails/app/views/people/_person.html.haml:1:in `_run_haml_app47views47people47_person46html46haml_locals_object_person'
/Users/paul/Documents/Projects/msvngit/rails/app/views/people/edit.html.haml:4:in `_run_haml_app47views47people47edit46html46haml'
grimen commented 14 years ago

validatious-on-rails running for me, but overall I would not recommend it for production yet (under heavy development, and acutally not really "released" yet - but got spread it seems), but this don't look like a validatious-on-rails error. As you see the stack trace don't have any validatious-on-rails-related calls. I would be pleased if you could help out debug this issue so we know why it appears...or at least throw together a failin test.

lapluviosilla commented 14 years ago

I'll try and figure it out, but I do know that I only get this error if I have validatious-on-rails installed. If I remove validatious-on-rails then it works just fine. You can also see that the error does have something to do with a validation function: "/opt/local/lib/ruby/gems/1.8/gems/formtastic-0.2.5/lib/formtastic.rb:477:in `options_require_validation?'"

Thanks

grimen commented 14 years ago

Yes, but validatious-on-rails is not extending ActiveRecord::Base - validation_reflection does that though. COuld you step through the stuff with debugger? Formtastic line 477 dont' match for me: "def input_simple(type, method, options)" =S

lapluviosilla commented 14 years ago

I'm using the latest version of formtastic "0.2.5". I just that if I go back to version "0.3.3" of validatious-on-rails the error goes away and starting from version "0.3.4" to "0.3.5" the error appears. At "0.3.3" the validations work perfectly. Changing formtastic versions doesn't seem to do anything. This is the commit that breaks it http://github.com/grimen/validatious-on-rails/commit/74edea852f6aa2c635b00941e4af5c598daf90c1.

I'll post a debug report in a bit.

grimen commented 14 years ago

This kind of error sometimes appear with nil-strings. I'll focus on the two high-priority issues until we got more info on this one. This one is not very obvious... xP

lapluviosilla commented 14 years ago

Heh heh, well I did dump a motherload. Sry about that. ;o)

Found out what "causes" the problem! I'm not sure exactly at what line it breaks, but it only breaks if I have "validates_presence_of" statements in the model with more than 1 property specified.

Look at the model above. If I change

validates_presence_of :first_name, :last_name

to

validates_presence_of :first_name
validates_presence_of :last_name

it starts working.

So, my guess is that your code is probably expecting a symbol or string and then it gets an array instead. I might be wrong, but that is definitely what is causing it though.

grimen commented 14 years ago

Ah, good find! Need to squash this one, smells like a easy task - and hopefully it is.

grimen commented 14 years ago

Sorry, but I can't reproduce this. I used the sample you posted - but commented out "self.full_name = full_name" because that should not work anyway. Everything validates as expected.

lapluviosilla commented 14 years ago

Ok, so I went through my fork of test-app and played around with it until I was able to reproduce the bug. First of all I added validatious-on-rails to the project. validatious-on-rails "0.3.7" doesn't seem to work with Rails 2.3.3 anymore so I updated to 2.3.4.

I then removed the formtastic plugin which was version "0.2.4" and used the "0.2.5" formtastic gem from gemcutter instead. After updating formtastic I can now reproduce the bug again. So, it looks like its a incompatibility between formtastic 0.2.5 and validatious-on-rails.

I already pushed my changes to my fork of test-app.

lapluviosilla commented 14 years ago

Oh, and just FYI "self.full_name = full_name" does work. It only works because I don't have a full_name setter defined, but you're right, "write_attribute" probably would be better.

grimen commented 14 years ago

OK, will check it out. It do sound like a Formtastic issue though, as I'm hardly touching the view helpers - just adding a class. =S

lapluviosilla commented 14 years ago

If I disable validatious-on-rails the error goes away, so the issue is definitely "triggered" by validatious-on-rails, but it could be a problem on the side of formtastic that just happens to come up when using validatious-on-rails.

grimen commented 14 years ago

Yes, something like that. It'll require the debugger to see what actually is happening, hopefully get time to solve it tomorrow.

grimen commented 14 years ago

Formtastic bug, fixed here (not pulled though):

http://github.com/grimen/formtastic/commit/9330ab99110ae3d159cd425c6f0bd930835126ea

grimen commented 14 years ago

Patch pulled into Formtastic just recently, closing this issue.