Need help with datebalks plugin

I am getting this error when using the datebalks plugin with a field_text call:

      <%= f.text_field :effective_from,                         :class => 'datebalks',                         :size => 12       -%>

NoMethodError in ClientsController#update

undefined method `effective_from_text=' for #<Client:0xb6ce88c4>

RAILS_ROOT: /home/byrnejb/Software/Development/Projects/proforma Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:200:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2117:in `send' ...

Request

Parameters:

{"commit"=>"Update", "entity"=>{"entity_legal_name"=>"Test Client Number One Ltd.", "entity_name"=>"The Very First Test Client", "entity_legal_form"=>"CORP"}, "_method"=>"put", "authenticity_token"=>"053225ec5f700f7ff759f8ba1e22970ac411315a", "client"=>{"effective_from_text"=>"yesterday", "client_credit_policy"=>"CASH", "client_status"=>"HOLD", "effective_from"=>"March 26, 2008", "superseded_after_text"=>"", "superseded_after"=>"", "client_credit_terms"=>"0"}, "id"=>"1"}

The author's documentation says this: --->

How Does it Work?

Datebalks is a small parser written in Javascript to which I've added a pinch of DHTML (the same dynarch calendar) and a dash of Low-pro love for unobtrusive elegance.

Lowpro just scans the page for input fields with a datebalks class. For each such input, lowpro adds a hidden field and links a pop-up calendar to it. As a programmer, all you need to do to get nice date fields is to remember to give them the datebalks class. That's all there is to it!

Under the covers, it transforms your date field a pair of input fields. The original field remains visible but will be renamed by smartly appending a _text to it's name (it's rails aware of course). The other input will be hidden, will be given the original field name and will hold the value of the parsed date in yyyy-mm-dd format. The popup calendar and a text label are also added to provide the user a point and click solution and some feedback.

---

So, my problem seems to be that these plugin generated hidden fields (effective_date_text and superceded_date_text) are getting passed back to the model, which of course does not have them. The blunt trauma solution is to add them as virtual attributes to the model. My question is, how do I get this work as described. Am I failing to do something that the author assumes that I know about?

If you use text_field_tag then it won't get submitted inside the client params and you should be ok.

Fred

Frederick Cheung wrote:

Frederick Cheung wrote:

I am getting this error when using the datebalks plugin with a field_text call:

    <%= f.text_field :effective_from,                       :class => 'datebalks',                       :size => 12     -%>

If you use text_field_tag then it won't get submitted inside the client params and you should be ok.

Fred

Results in:

undefined method `text_field_tag' for #<ActionView::Helpers::FormBuilder:0xb6ce0cdc>

I am calling this inside a forms_for as a fields_for nest.

Are you doing f.text_field_tag ? If so, don't. Just plain old <%=
text_field_tag ... %> Fred

Frederick Cheung wrote:

Are you doing f.text_field_tag ? If so, don't. Just plain old <%= text_field_tag ... %> Fred

The whole point is to return a valid date in effective_from and superseded_after for Client. If I drop to field_text_tag then how to I get the value passed back to the active record? The form works now but the table does not get updated.

Is there no way to get this to work within the context of a form builder?

Frederick Cheung wrote:

Are you doing f.text_field_tag ? If so, don't. Just plain old <%= text_field_tag ... %> Fred

The whole point is to return a valid date in effective_from and superseded_after for Client. If I drop to field_text_tag then how to I get the value passed back to the active record? The form works now but the table does not get updated.

Is there no way to get this to work within the context of a form builder?

Sorry, I'd slightly misunderstood the problem. You could always just remove the effective_from_text param from the hash.

Fred

Frederick Cheung wrote:

Sorry, I'd slightly misunderstood the problem. You could always just remove the effective_from_text param from the hash.

Fred

That is what I am trying to accomplish now. The questions are: How do I do this and where do I do it?

params[:client].delete_if { |k,v| k =~ /*_text/ } seems the way but I cannot get this to work as I expect in console.

The second question is where do I do this? In the controller?

Regards,

James Byrne wrote:

params[:client].delete_if { |k,v| k =~ /*_text/ } seems the way but I cannot get this to work as I expect in console.

This works much better:

a.delete_if { |k, v| c = /.*_text/; c =~ k.to_s }

SO, I am left with the second question. Where?

That is what I am trying to accomplish now. The questions are: How do I do this and where do I do it?

params[:client].delete_if { |k,v| k =~ /*_text/ } seems the way but I cannot get this to work as I expect in console.

I'd do it in the controller. You regular expression is bust, i think you want /_text$/

Fred