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
James Hughes wrote:> 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?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.
On 12/9/05, Mark Reginald James <mrj-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> James Hughes wrote: > > 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? > > 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
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.
On 12/9/05, Mark Reginald James <mrj-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> 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.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
On 12/9/05, Mark Reginald James <mrj-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> 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.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
On 12/12/05, James Hughes <hughes.james-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/9/05, Mark Reginald James <mrj-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> > > > 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.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