Forum: Ruby on Rails observe_field doing nothing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E74a19a983b0da1c671de90b341e7c06?d=identicon&s=25 hughes.james (Guest)
on 2005-12-10 00:53
(Received via mailing list)
Hi

Here's the code:

<%= select_tag "extra", options_for_select(@extra_fields) %>

<% observe_field "extra", :update => "extra_fields",
                :url => {:action => :new_edit_field} %>

I want to select from the dropdown, and have a controller that
generates a text field for the option selected and puts it in the
extra_fields div.

When I do the select, there is complete silence: webrick does not log
receipt of a POST, and I have a breakpoint in the new_edit_field
action which is never hit.

Any ideas what I'm doing wrong?

Thanks!

--
James Hughes
Web application developer
Centre for Health Services and Policy Research
Vancouver, BC
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 mrj (Guest)
on 2005-12-10 01:05
(Received via mailing list)
James Hughes wrote:
> generates a text field for the option selected and puts it in the
> extra_fields div.
>
> When I do the select, there is complete silence: webrick does not log
> receipt of a POST, and I have a breakpoint in the new_edit_field
> action which is never hit.
>
> Any ideas what I'm doing wrong?

Did you leave the '=' out of the erb tag for the observe_field call?

--
We develop, watch us RoR, in numbers too big to ignore.
E74a19a983b0da1c671de90b341e7c06?d=identicon&s=25 hughes.james (Guest)
on 2005-12-10 04:41
(Received via mailing list)
On 12/9/05, Mark Reginald James <mrj@bigpond.net.au> wrote:
> > I want to select from the dropdown, and have a controller that
> > generates a text field for the option selected and puts it in the
> > extra_fields div.
> >
> > When I do the select, there is complete silence: webrick does not log
> > receipt of a POST, and I have a breakpoint in the new_edit_field
> > action which is never hit.
> >
> > Any ideas what I'm doing wrong?
>
> Did you leave the '=' out of the erb tag for the observe_field call?

I've tried it both ways, with the same result. My understanding is
that the '=' is used for code that is going to dump some output? So it
would seem that the '=' is not required, but I don't know for sure.
jh

--
James Hughes
Web application developer
Centre for Health Services and Policy Research
Vancouver, BC
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 mrj (Guest)
on 2005-12-10 06:52
(Received via mailing list)
James Hughes wrote:

>>><% observe_field "extra", :update => "extra_fields",
>>>                :url => {:action => :new_edit_field} %>
>>
>>Did you leave the '=' out of the erb tag for the observe_field call?
>
> I've tried it both ways, with the same result. My understanding is
> that the '=' is used for code that is going to dump some output? So it
> would seem that the '=' is not required, but I don't know for sure.

You definitely need the '=', because it has to spit out a script
section.

I can see another problem:
            {:action => :new_edit_field}
should be
            {:action => 'new_edit_field'}

Actions and controllers needing to be strings rather than symbols
is one of Rails' biggest gotchas.  As a newbie I certainly fell
prey to it.  Is there a good reason for it?

If it still doesn't work, use your browser to check the generated
HTML source, and work out what it will do.

--
We develop, watch us RoR, in numbers too big to ignore.
E74a19a983b0da1c671de90b341e7c06?d=identicon&s=25 James Hughes (Guest)
on 2005-12-11 23:06
(Received via mailing list)
On 12/9/05, Mark Reginald James <mrj@bigpond.net.au> wrote:
>
> You definitely need the '=', because it has to spit out a script
> section.

Ah, of course, that makes sense. I'll put it back, but that's still
not my whole problem...as you point out:
>
> I can see another problem:
>             {:action => :new_edit_field}
> should be
>             {:action => 'new_edit_field'}
>
> Actions and controllers needing to be strings rather than symbols
> is one of Rails' biggest gotchas.  As a newbie I certainly fell
> prey to it.  Is there a good reason for it?

Is it even consistent? I'm not at work right now so I can't check but
I seem to recall it working for me some of the time. Nevertheless, I
also know that I've 'fixed' things in the past by making this change,
so, will do.
>
> If it still doesn't work, use your browser to check the generated
> HTML source, and work out what it will do.
>
Good plan. Thanks for the Monday morning to-do list ;)
jh
--
James Hughes
Web application developer
Centre for Health Services and Policy Research
Vancouver, BC
E74a19a983b0da1c671de90b341e7c06?d=identicon&s=25 James Hughes (Guest)
on 2005-12-12 20:04
(Received via mailing list)
On 12/9/05, Mark Reginald James <mrj@bigpond.net.au> wrote:
>
> prey to it.  Is there a good reason for it?
>
> If it still doesn't work, use your browser to check the generated
> HTML source, and work out what it will do.

Here's is what is being generated:

//<![CDATA[
new Form.Element.EventObserver('extra', function(element, value) {new
Ajax.Updater('extra_fields', '/users/new_edit_field',
{asynchronous:true, evalScripts:true, parameters:value})})
//]]>

I've changed the action from a symbol to a string, with no effect. The
js code above does not cause a post to be sent to the server on
selection of an option from the select list. Guess I'll have to dig
into the javascript to see what's going on.


--
James Hughes
Web application developer
Centre for Health Services and Policy Research
Vancouver, BC
E74a19a983b0da1c671de90b341e7c06?d=identicon&s=25 James Hughes (Guest)
on 2005-12-12 21:04
(Received via mailing list)
On 12/12/05, James Hughes <hughes.james@gmail.com> wrote:
> On 12/9/05, Mark Reginald James <mrj@bigpond.net.au> wrote:

> //]]>
>
> I've changed the action from a symbol to a string, with no effect. The
> js code above does not cause a post to be sent to the server on
> selection of an option from the select list. Guess I'll have to dig
> into the javascript to see what's going on.

Ok, found the problem. My prototype.js was dangerously out of date. It
didn't even have the EventObserver function in it. Puzzling as to why
no javascript error was being reported though.

thanks,
jh


--
James Hughes
Web application developer
Centre for Health Services and Policy Research
Vancouver, BC
This topic is locked and can not be replied to.