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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
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.