Hi friends,

How to use javascript variables in ruby.

i have activity id on a_id

function(a_id)
{
("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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.

Search Discussions

  • Jordon Bedwell at Nov 13, 2013 at 1:56 pm

    On Wed, Nov 13, 2013 at 7:30 AM, Daynthan Kabilan wrote:
    function(a_id)
    {
    ("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@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    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.
  • Jordon Bedwell at Nov 13, 2013 at 1:58 pm

    On Wed, Nov 13, 2013 at 7:55 AM, Jordon Bedwell wrote:
    On Wed, Nov 13, 2013 at 7:30 AM, Daynthan Kabilan wrote:
    function(a_id)
    {
    ("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@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    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.
  • Scott Ribe at Nov 13, 2013 at 2:32 pm

    On Nov 13, 2013, at 6:30 AM, Daynthan Kabilan wrote:

    Hi friends,

    How to use javascript variables in ruby.

    i have activity id on a_id

    function(a_id)
    {
    ("activity_id = ? ", a_id)
    }

    how can solve it
    It'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@elevated-dev.com
    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@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    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.
  • Daynthan Kabilan at Nov 13, 2013 at 2:40 pm
    hi

    here i have mention example code

    <script type="text/javascript">

    var js_name="daya";

    ("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@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    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.
  • Walter Lee Davis at Nov 13, 2013 at 2:45 pm

    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";

    ("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@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    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@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    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.
  • Scott Ribe at Nov 13, 2013 at 2:52 pm

    On Nov 13, 2013, at 7:40 AM, Daynthan Kabilan wrote:

    here i have mention example code
    OK, 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@elevated-dev.com
    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@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    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.
  • Colin Law at Nov 13, 2013 at 2:55 pm

    On 13 November 2013 14:40, Daynthan Kabilan wrote:
    hi

    here i have mention example code

    <script type="text/javascript">

    var js_name="daya";

    ("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@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 13, '13 at 1:30p
activeNov 13, '13 at 2:55p
posts8
users5
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase