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:insend’

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?

On 25 Mar 2008, at 17:36, James B. 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

Frederick C. wrote:

On 25 Mar 2008, at 17:36, James B. 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.

Frederick C. 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?

On 25 Mar 2008, at 18:31, James B. wrote:

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 C. 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,

On 25 Mar 2008, at 18:01, James B. wrote:

                  :size => 12

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

James B. 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?

In case anyone else runs into this problem then the final step is to
modify the update method inside the appropriate controller from:

  if @client.update_attributes(params[:client])

to:
if @client.update_attributes(params[:client].delete_if
{ |k, v| c = /.*_text/; c =~ k.to_s })

I felt that the default extension used by datebalks, '_text’, was
asking for a name collision at some point, given what I am doing here. I
therefore modified datebalks.js to use an extension of ‘__dteblk’ and
modified the regesxp to c = /.
__dteblk/ instead.

On Mar 25, 7:29 pm, James B. [email protected]
wrote:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs