Ronald Zhang
2013-Apr-19 15:03 UTC
How to get value from Javascript Input in Ruby Controller?
I currently have javascript in my view and it contains inputs so users can input values <input type = "text" name = "date8" id = "date8" value = "" size =25 > I want to be able to access the value in this input once a method in my controller is called. How can I do this? params[date8] does not work which makes sense since it isnt a ruby textfield. Anyone have any ideas? Thanks -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Yong Gu
2013-Apr-19 15:12 UTC
Re: How to get value from Javascript Input in Ruby Controller?
It depends how you send that value to the controller. If you use a form to submit data, then params[:date8] would work. If you use a link, then you need to append the value to the link, like http://www.yourdomain.com/controller/method?date8=value -- Yong Gu Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Friday, April 19, 2013 at 11:03 PM, Ronald Zhang wrote:> I currently have javascript in my view and it contains inputs so users > can input values > > <input type = "text" name = "date8" id = "date8" value = "" size =25 > > > I want to be able to access the value in this input once a method in my > controller is called. How can I do this? params[date8] does not work > which makes sense since it isnt a ruby textfield. Anyone have any ideas? > Thanks > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Ronald Zhang
2013-Apr-19 15:22 UTC
Re: How to get value from Javascript Input in Ruby Controller?
Thanks for the reply! I currently have a _form.html.erb file which contains all the javascript/html. When I do params[:date8], I see that there isn''t anything in there. Just an empty string even though something was typed into it. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Yong Gu
2013-Apr-19 15:32 UTC
Re: Re: How to get value from Javascript Input in Ruby Controller?
check the logs to find out whether other params were passed to the controller or not. Is the input in inside the form? How do you use javascript on that input field? -- Yong Gu Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Friday, April 19, 2013 at 11:22 PM, Ronald Zhang wrote:> Thanks for the reply! I currently have a _form.html.erb file which > contains all the javascript/html. When I do params[:date8], I see that > there isn''t anything in there. Just an empty string even though > something was typed into it. > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Ronald Zhang
2013-Apr-19 15:50 UTC
Re: How to get value from Javascript Input in Ruby Controller?
Currently the javascript contains functions for a calendar app so users do not have to insert the date manually Here is some of the HTMl <div> <form name = "calendar1"> <input type = "text" name = "date1" id = "date1" value = "" size =25 readonly style = "border:0px;"> <A HREF = "#" onclick = "cal.select(document.forms[''calendar1''].date1,''anchor1'',''MM/dd/yyyy'');return false;" NAME = "anchor1" ID = "anchor1">select date</A> </form> </div> The calendar app works fine, when I test it everything gets inserted correctly into the entry field/input. Its trying to get the controller to recognize the value of the input. Here is my controller. def create con = Mysql.new ''xx.xx.x.x'',''xxxx'',''xxxx'', ''worksheet'' date1 = params[:date1] rs = con.query ''INSERT INTO test VALUES ("''+date1.to_s+''")'' end I know the method is called and everything is linked because the database has new entries in it. However, I only see an empty string with nothing in it. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Ronald Zhang
2013-Apr-19 16:16 UTC
Re: How to get value from Javascript Input in Ruby Controller?
Is it possible to pass in the value of date1 into the method when the button is pressed? That way I wont have to find a way to reference everything in the controller. If so I can I change my button_to to reflect that? <div> <%= button_to "Create", action:"create"%> </div> -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Yong Gu
2013-Apr-19 16:29 UTC
Re: Re: How to get value from Javascript Input in Ruby Controller?
Please not. You can either append the value to the url or put the value inside the form. You can check whether the date1 was posted to the server. Use web inspector to see the posted data. If the date1 was not even included in the posted data, then you need to check your html and javascript. Or if the date1 was included but it is blank, then you need to figure out why it is blank. -- Yong Gu Sent with Sparrow (http://www.sparrowmailapp.com/?sig) On Saturday, April 20, 2013 at 12:16 AM, Ronald Zhang wrote:> Is it possible to pass in the value of date1 into the method when the > button is pressed? That way I wont have to find a way to reference > everything in the controller. If so I can I change my button_to to > reflect that? > > <div> > <%= button_to "Create", action:"create"%> > </div> > > -- > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org (mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org). > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists
2013-Apr-19 22:50 UTC
Re: Re: How to get value from Javascript Input in Ruby Controller?
On Fri, Apr 19, 2013 at 10:50 AM, Ronald Zhang <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Currently the javascript contains functions for a calendar app so users > do not have to insert the date manually > > Here is some of the HTMl > <div> > <form name = "calendar1"> > <input type = "text" name = "date1" id = "date1" value = "" size =25 > readonly style = "border:0px;"> > <A HREF = "#" onclick > "cal.select(document.forms[''calendar1''].date1,''anchor1'',''MM/dd/yyyy'');return > false;" NAME = "anchor1" ID = "anchor1">select date</A> > </form> > </div> > > The calendar app works fine, when I test it everything gets inserted > correctly into the entry field/input. Its trying to get the controller > to recognize the value of the input. Here is my controller. > def create > con = Mysql.new ''xx.xx.x.x'',''xxxx'',''xxxx'', ''worksheet'' > date1 = params[:date1] > rs = con.query ''INSERT INTO test VALUES ("''+date1.to_s+''")'' > end > I know the method is called and everything is linked because the > database has new entries in it. However, I only see an empty string with > nothing in it.Install the ruby debugger. Then insert the debugger to start at this point: def create con = Mysql.new ''xx.xx.x.x'',''xxxx'',''xxxx'', ''worksheet'' debugger date1 = params[:date1] rs = con.query ''INSERT INTO test VALUES ("''+date1.to_s+''")'' end Then, when the debugger starts up, check to see what params contains:> eval params.inspect-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.