Equivalent to observe_field in rails 3

Hi every one,
i need something like populating all the states
when a particular country selected. My exact requirement is, in my
project management tool, when a project is selected all of its
activities should be populated in the next drop down. I think before
rails 3 it can be done using observe_field tag. But how to do that in
rails 3 ( 3.0.10 to be precise) .

Hi Venkata,

On Sun, Jan 8, 2012 at 1:57 AM, venkata reddy
[email protected] wrote:

Hi every one,
i need something like populating all the states
when a particular country selected. My exact requirement is, in my
project management tool, when a project is selected all of its
activities should be populated in the next drop down. I think before
rails 3 it can be done using observe_field tag. But how to do that in
rails 3 ( 3.0.10 to be precise) .

AFAIK, the ‘observe…’ helpers have not been replicated for jquery (
I miss them, too) so the easiest way is to swap out jquery and use
prototoype.js. jQuery is now the default, but you can continue to use
prototype.js if you like.

Best regards,
Bill

As i already mentioned above, i am using 3.0.10 here and the default
js library is prototype. But still i am not able make observe_field
working.

Any ideas?

On Sun, Jan 8, 2012 at 11:40 AM, venkata reddy
[email protected] wrote:

As i already mentioned above, i am using 3.0.10 here and the default
js library is prototype. But still i am not able make observe_field
working.

Missed that. Sorry. In that case I’d need to know more about what
‘not working’ means. You might want to start by looking at the page
source. Is the ajax code there? If so, is its url pointing to the
action you expect it to be pointing to? Using Firebug (you can’t do
much debugging of ajax without it), when the field changes is the ajax
firing and generating the expected post in the console? If you
haven’t already, put some logging in the controller action. Is it
getting fired? With the expected parameter(s)? Etc…

HTH,
Bill

looking at
http://apidock.com/rails/v2.3.8/ActionView/Helpers/PrototypeHelper/observe_field

i thinkt that method is opt out on 2.3.8

maybe #88 Dynamic Select Menus - RailsCasts

there is a revised version, but it’s for subscriber only

Ahmy Y.

looking here solved my problem.

http://gregmoreno.ca/rails-3-upgrade-part-4-prototype-helpers-and-javascript/

I think observe_field is a good method to be included. Can’t
understand why it’s not there.
Thank you all!

observe_field was deprecated as rails 3 is towards being javascript
agnostic and requires the developer to have a good grasp of
javascript.

I am getting this error, when tried to access the form.
NoMethodError in People#new
Showing /home/local/PENNYWISE/venkatab/Desktop/rails/dynalists/app/
views/people/_form.html.erb where line #26 raised:
undefined method `observe_field’ for #<#Class:0x007f511c403ed0:
0x007f511c347cd0>Extracted source (around line #26):
23: <%= f.label :state_id, “state” %>
24:

25: <%= f.collection_select :state_id,
@states, :id, :name %>26: <%=
observe_field :person_country_id, :url => { :action =>
“update_state_div”} , :with => :person_country_id %>27:
28:

29:
Trace of template inclusion: app/ views/people/new.html.erb

i am following this

, and doing the same.I doubt prototype in rails3 have no method of
observe_field.

On Sun, Jan 8, 2012 at 1:27 PM, venkata reddy
[email protected]wrote:

Hi every one,
i need something like populating all the states
when a particular country selected. My exact requirement is, in my
project management tool, when a project is selected all of its
activities should be populated in the next drop down. I think before
rails 3 it can be done using observe_field tag. But how to do that in
rails 3 ( 3.0.10 to be precise) .

Hi venkat

This might be helpful to u…

K.M. wrote in post #1040052:

observe_field was deprecated as rails 3 is towards being javascript
agnostic and requires the developer to have a good grasp of
javascript.
Unobtrusive JavaScript in Rails 3 — Simone Carletti

+1

I also agree with the deprecation, and ultimate removal, of the
observe_field helpers. The same behavior can be duplicated with jQuery.
Rails should not include helpers that are tightly bound to any specific
JavaScript library.