Hi,
this is all new to me, so please don''t get upset if my questions are
very obvious. I''m trying to display a ruby variable through JS alert
function in the controller. Hope it makes sense, here''s my example:
myController.rb
class ...blah... < ApplicationCon...blah...
def someAction
@myRvariable = "lala"
render :text => "alert(<%=@myRvariable%>)",
:content_type => "text/javascript"
end
end
myIndex.rhtml
<p>
<%= link_to_remote "Display Rvariable",
:url => {:action => "someAction"} %>
</p>
So, I want to see an alertbox with "lala" when I click the link.
Thank you very much!
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Okey, nevermind that last post, I''ve found a solution. It''s
like this;
class ...blah....
def someAction
@myRvariable = "lala"
render :update do |page|
page.alert @myRvariable
end
end
end
I would be really grateful for explanation of this, I still don''t know
why it works, and why the previous doesn''t.
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 post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi Ma Mr, Ma Mr wrote:> I would be really grateful for explanation of this, > I still don''t know why it works, and why the > previous doesn''t.The short answer is that the element (created by link_to_remote) that submitted the request to the server told the server via the message type (XMLHttpRequest) that the browser expected JS, not HTML, returned. Your first attempt used render which returned just the HTML you wanted displayed. Your second returned the HTML along with the JS to display it. hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---