1

In the HTML header this small javascript works:

application.html.erb

<script type="text/javascript">
               alert("<%= escape_javascript(render('resources/positions')) %>");
</script>

But When I tried to put the same code in a js.erb file, it doesn't work.

I tried to inlcude the file, but not working both ways:

<script src="/assets/resources.js.erb" type="text/javascript"></script>
<%= javascript_include_tag 'resources' %>

app/assets/javascripts/resources.js.erb

alert("<%= escape_javascript(render('resources/positions')) %>");

any ideas ?

Thanks in advance for any help.

7
  • I'd check in the generated html that the file you're getting (/assets/resources.js) exists and contains what you expect Commented Jul 31, 2012 at 14:28
  • Yes I checked the generated html Commented Jul 31, 2012 at 14:38
  • So what's the content of /assets/resources.js? Also check the JS console to see if there's any error message Commented Jul 31, 2012 at 14:39
  • there is no errors, and the content is empty... :( Commented Jul 31, 2012 at 14:56
  • You might have a problem with the asset pipeline then ... what's your configuration for it ? Commented Jul 31, 2012 at 14:58

1 Answer 1

1

Sounds like a problem with the asset pipeline.

Try adding

config.serve_static_assets = true

In development.rb

Sign up to request clarification or add additional context in comments.

8 Comments

restarted the server and still the same.. I have to use javascript_include_tag ?
<%= javascript_include_tag 'resources' %> and here is my file app/assets/javascripts/resources.js.erb
Yes use javascript_include_tag
Even a simple alert(1); doesn't work.. You're sure it's the good path app/assets/javascripts/resources.js.erb ?
I don't know, it's your app! How does the generated html script tag look?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.