Neil Bye
2010-Jun-13 11:50 UTC
Problem submiting value, form_for, link-to-remote, javascrip
This is my form. It creates a comment in the database but won''t pass the ''body'' value. I think the problem is passing the variable to javascript. Can anyone help? <% form_for :comment, :url=>story_comments_path(@story), :name => ''form'' do |form| %> <fieldset> <label for="login">Comment:</label> <div id="body"><%= form.text_field :body %></div> <%= link_to_remote(''comment'',{ :url => {:controller => ''comments'' , :action => ''create'', :story_id => @story.id, :method => ''get'', :with => ''serialize_fields()'' }}) %> </fieldset> <% end %> This is the javascript. <script> function serialize_fields(){ var fields = new Array(); fields.push(Form.Element.serialize(''document.form.body'')); return fields.join(''&''); } </script> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Jun-13 15:42 UTC
Re: Problem submiting value, form_for, link-to-remote, javascrip
On Jun 13, 12:50 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> This is my form. It creates a comment in the database but won''t pass the > ''body'' value. I think the problem is passing the variable to javascript. > Can anyone help? >Your serialize_form method looks borked. You could use the remote_form_for method alternatively, prototype already provides a serialise method for forms - $(''id_of_the_form'').serialize() will serialise all then inputs in the form Fred> <% form_for :comment, :url=>story_comments_path(@story), :name => > ''form'' do |form| %> > <fieldset> > <label for="login">Comment:</label> > <div id="body"><%= form.text_field :body %></div> > <%= link_to_remote(''comment'',{ :url => > {:controller => ''comments'' , > :action => ''create'', > :story_id => @story.id, > :method => ''get'', > :with => > ''serialize_fields()'' }}) %> > </fieldset> > <% end %> > > This is the javascript. > > <script> > function serialize_fields(){ > var fields = new Array(); > fields.push(Form.Element.serialize(''document.form.body'')); > return fields.join(''&'');} > > </script> > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
AliReza Taleghani
2010-Jun-13 16:13 UTC
Re: Re: Problem submiting value, form_for, link-to-remote, javascrip
Dear Fred; so thanks, for ur help. am so new to ROR, and was so interested on AJAX, i used the ActiveScaffod instead of it and all is okey. bytheway, tnx2much @};- On Sun, Jun 13, 2010 at 8:12 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Jun 13, 12:50 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > This is my form. It creates a comment in the database but won''t pass the > > ''body'' value. I think the problem is passing the variable to javascript. > > Can anyone help? > > > > Your serialize_form method looks borked. You could use the > remote_form_for method alternatively, prototype already provides a > serialise method for forms - $(''id_of_the_form'').serialize() will > serialise all then inputs in the form > > Fred > > > > > > > > > <% form_for :comment, :url=>story_comments_path(@story), :name => > > ''form'' do |form| %> > > <fieldset> > > <label for="login">Comment:</label> > > <div id="body"><%= form.text_field :body %></div> > > <%= link_to_remote(''comment'',{ :url => > > {:controller => ''comments'' , > > :action => ''create'', > > :story_id => @story.id, > > :method => ''get'', > > :with => > > ''serialize_fields()'' }}) %> > > </fieldset> > > <% end %> > > > > This is the javascript. > > > > <script> > > function serialize_fields(){ > > var fields = new Array(); > > fields.push(Form.Element.serialize(''document.form.body'')); > > return fields.join(''&'');} > > > > </script> > > -- > > Posted viahttp://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Regards, AliRezaTaleghani. 0936 322 4069 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Neil Bye
2010-Jun-16 12:59 UTC
Re: Problem submiting value, form_for, link-to-remote, javascrip
Neil Bye wrote:> This is my form. It creates a comment in the database but won''t pass the > ''body'' value. I think the problem is passing the variable to javascript. > Can anyone help? > > <% form_for :comment, :url=>story_comments_path(@story), :name => > ''form'' do |form| %> > <fieldset> > <label for="login">Comment:</label> > <div id="body"><%= form.text_field :body %></div> > <%= link_to_remote(''comment'',{ :url => > {:controller => ''comments'' , > :action => ''create'', > :story_id => @story.id, > :method => ''get'', > :with => > ''serialize_fields()'' }}) %> > </fieldset> > <% end %> > > This is the javascript. > > <script> > function serialize_fields(){ > var fields = new Array(); > fields.push(Form.Element.serialize(''document.form.body'')); > return fields.join(''&''); > } > </script>I tried this too :with=>"''body'' + $F(''body'')" That doesn''t work either. How can I pass this parameter? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.