Syntax for observe_field( :with =>

Greetings!

What is up with the syntax of this thing? I mean, if the only thing I
can send back using :with is the field being observed, then why in the
world is the syntax so convoluted? For example, what I’ve been able to
get working is:

<%= text_field_tag(‘date’, illness_date, :size => 30) %>


<%= observe_field(‘date’, :url => {:action => ‘update_date’, :id =>
illness_id}, :with => “‘idate=’+$(‘date’).value” ) %>

Of course, maybe I’m just doing it wrong. I suppose it might make some
sense if it’s possible to send more than one params value back with the
:with option. Does anybody know anything about how that might be
possible? I’ve spent a day and a half trying to figure it out and
haven’t been able to get anything but the above to work.

TIA,
Bill

Hi Bill,

You can send anything back to your script. The syntax is pure
javascript
that is eval’d. You can use it to build a custom parameter string. I’m
not
sure if it needs to be escaped to be url encoded or not.

:with => %q{“idate=” + $(‘date’).value + “&some_other_value=” +
$(‘some_other_field’).value}

Hope this is strictly correct. I’m sure someone will correct me
otherwise
:slight_smile: at least I hope so.

Hi Daniel,

Thanks. I haven’t tried the %q syntax (although that’s about the only
thing I haven’t tried!). I’ll give it a shot. I did find something on
the wiki just after I sent my original post that implies you can only
send back one params value but you can put a bunch of stuff into the
one string you’ll get back and then parse out the pieces. I definitely
hope your approach works, but at least it looks like there’s a way to do
what I need, even if it’s coyote-ugly :wink:

Thanks again,
Bill
----- Original Message -----
From: Daniel N
To: [email protected]
Sent: Monday, June 26, 2006 8:57 AM
Subject: [Norton AntiSpam] Re: [Rails] syntax for observe_field( :with
=>

Hi Bill,

You can send anything back to your script. The syntax is pure
javascript that is eval’d. You can use it to build a custom parameter
string. I’m not sure if it needs to be escaped to be url encoded or
not.

:with => %q{“idate=” + $(‘date’).value + “&some_other_value=” +
$(‘some_other_field’).value}

Hope this is strictly correct. I’m sure someone will correct me
otherwise :slight_smile: at least I hope so.

On 6/26/06, Bill W. [email protected] wrote:
Greetings!

What is up with the syntax of this thing?  I mean, if the only thing 

I can send back using :with is the field being observed, then why in the
world is the syntax so convoluted? For example, what I’ve been able to
get working is:

<%= text_field_tag('date', illness_date, :size => 30) %></p>
<%= observe_field('date', :url => {:action => 'update_date', :id => 

illness_id}, :with => “‘idate=’+$(‘date’).value” ) %>

Of course, maybe I'm just doing it wrong.  I suppose it might make 

some sense if it’s possible to send more than one params value back with
the :with option. Does anybody know anything about how that might be
possible? I’ve spent a day and a half trying to figure it out and
haven’t been able to get anything but the above to work.

TIA,
Bill

_______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

On 6/27/06, Bill W. [email protected] wrote:

Yeah, it is very ugly. I guess you could wrap it up into a helper.
There’s
no doubt a much better way to do this.

def with_fields_for_observe( *fields )
fields.flatten!
out = “”
join = “”
fields.each do |field|
out << join << “’#{field.to_s}=’ + $(’#{field.to_s}’).value”
join = " + ‘&’ + "
end
out
end

Then you could call the with parameter with
:with => with_fields_for_observe( :a_field_id, ‘some_other_id’,
[:yet_another_id, :last_one] )

The access in your controller should be similar to a normal parameter
string. Best to check the output tho.

Hope this minimises the ugly to a reasonable level. :wink:

Thanks again,

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