javascript...

i've written script function ganesh.js inside "public/javascripts/"
path..

ganesh.js..

function gan()
{
alert('hai');
}
ive called that function in show.rhtml file like

<%= image_tag('e.image', {:id => e.id, :onload => gan()}) %>

i cant able to call that function ...is there any other way to enable
javascript function in ruby rails..pls help..

if i wrote script inside rhtml its working ....

<%=link_to_function("add","gan()")%>
<script type="text/javascript">
function gan()
{
  alert('hai');
}
</script>

how to enable javascript function from public/javascripts folder...

i've written script function ganesh.js inside "public/javascripts/"
path..

ganesh.js..

function gan()
{
alert('hai');
}
ive called that function in show.rhtml file like

<%= image_tag('e.image', {:id => e.id, :onload => gan()}) %>

that would need to be

<%= image_tag('e.image', {:id => e.id, :onload => "gan()"}) %>

You would need to include the relevant javacript file using
javascript_include_tag

Fred

It may be one of the following two reasons for getting the problem.

  1. You have not included the relevant javascript in the rhtml file.
     The following statement should be there in the rhtml file.
       <%= javascript_include_tag 'ganesh.js' %>

  2. You have not called the javascript method inside quotes.
     Try with,
       <%= image_tag('e.image', {:id => e.id, :onload => "gan();"}) %>

THANK U VERY MUCH Karthi .....IT WORKS FINE...