Hi friends, How to use javascript variables in ruby. i have activity id on a_id function(a_id) { <%@foo=Activity.where("activity_id = ? ", a_id) } how can solve it -- 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 To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADKeJyTrV2TvTk1mLL_2h0YRPzR%2B0YdmdhK%2BbnTWCyV89haDbQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On Wed, Nov 13, 2013 at 7:30 AM, Daynthan Kabilan <dayanthan86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> function(a_id) > { > <%@foo=Activity.where("activity_id = ? ", a_id) > }Name it: app/assets/javascript/file.js.erb and it will go through ERB. -- 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 To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAM5XQnxWgd2CG-WWvR_t5mJXkMtSvWGUYCF9rV-%3DuESSp2TTPA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On Wed, Nov 13, 2013 at 7:55 AM, Jordon Bedwell <envygeeks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Nov 13, 2013 at 7:30 AM, Daynthan Kabilan <dayanthan86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> function(a_id) >> { >> <%@foo=Activity.where("activity_id = ? ", a_id) >> } > > Name it: app/assets/javascript/file.js.erb and it will go through ERB.Actually I think I''m wrong try: http://railscasts.com/episodes/324-passing-data-to-javascript?view=asciicast -- 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 To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAM5XQnxRpWeBj-7mcVk46_DTX12y81iKbypiKDkVJ4cGU8%3Daog%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 13, 2013, at 6:30 AM, Daynthan Kabilan <dayanthan86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi friends, > > How to use javascript variables in ruby. > > i have activity id on a_id > > function(a_id) > { > <%@foo=Activity.where("activity_id = ? ", a_id) > } > > how can solve itIt''s not at all clear to me what you are asking, but remember: - Ruby runs on the server; - Javascript runs in the browser. - Sometimes Ruby on the server is used to create/modify Javascript to be run in the browser. -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- 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 To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CA4EA9DE-9178-48C9-B4C5-81B3140A974A%40elevated-dev.com. For more options, visit https://groups.google.com/groups/opt_out.
hi here i have mention example code <script type="text/javascript"> var js_name="daya"; <%=@user=User.where("name=?", js_name%> alert("<%=@user%>"); </script > -- 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 To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADKeJyTqA%3DZ44f1RQeTtm5j8%3DpXQMessnu%3DEpm4WTMDGu33jbA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 13, 2013, at 9:40 AM, Daynthan Kabilan wrote:> hi > > here i have mention example code > > <script type="text/javascript"> > > var js_name="daya"; > > <%=@user=User.where("name=?", js_name%> > > alert("<%=@user%>"); > > </script > >If you''re going to use Erb in your JavaScript, then you must name your file whatever.js.erb. Then your <%= %> will expand to be whatever the local value of @user is at the moment that script is requested. You will need a controller, too, and your request will need to have some context around it. If your controller had a respond_to block in it, and your JavaScript file was named sensibly for the controller method, then this would Just Workâ˘, respond_to do |format| format.js { render :layout => false } format.html end Walter>> -- > 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 > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADKeJyTqA%3DZ44f1RQeTtm5j8%3DpXQMessnu%3DEpm4WTMDGu33jbA%40mail.gmail.com. > 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 To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0A6EB8BA-E4BB-4726-8223-30394BA0C398%40wdstudio.com. For more options, visit https://groups.google.com/groups/opt_out.
On Nov 13, 2013, at 7:40 AM, Daynthan Kabilan <dayanthan86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> here i have mention example codeOK, evaluate that code in light of what I said previously: - Ruby runs on the server; - Javascript runs in the browser. Now: 1) What do you think that code will do??? 2) What are you actually trying to accomplish? -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- 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 To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/F12AB1F0-2F7D-4C31-B71B-608797293FA4%40elevated-dev.com. For more options, visit https://groups.google.com/groups/opt_out.
On 13 November 2013 14:40, Daynthan Kabilan <dayanthan86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi > > here i have mention example code > > <script type="text/javascript"> > > var js_name="daya"; > > <%=@user=User.where("name=?", js_name%>Remember the above is evaluated on the /server/ before the page is rendered. js_name is not meaningful at that time. Colin -- 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 To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLu5JA8OhDZfu_GbAMbVc0svwdSiBKynPCq9-bVkN9pwuw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.