Hi,
I’m just getting started playing around with Ruby. So far I’ve been able
to resolve all issues that have popped up on my own, but this particular
one has been giving me headaches for way too long now.
The problem is that I can’t seem to be able to include javascript files
into my pages. I’m using the javascript_include_tag to do this, and I’ve
verified that the generated path is correct and points to the file that
I want to include.
Let’s do an example:
A line in the generated html code looks like this:
In /public/javascript I have a file called user_login.js that has a
function called user_signup. Then, later in the html file, I have
something like this:
However, when I submit the form, the user_signup function is apparently
undefined. I have verified through various means that the problem indeed
seems to be that the file is not included, e.g. if I include an
alert(‘OK’) on the top of my js file, this does not get called.
Now, some details. I am using the fast-CGI dispatcher via a rewrite
condition in .htaccess. However, I have not found anything anywhere
saying that you need to preclude the javascripts path there, and what’s
more, when I try do so with something like
RewriteCond %{REQUEST_URI} ^/javascripts/(.*)$ [OR]
… it fails; a request for /javascripts/whatever still goes to the
dispatcher.
Leaving this aside, I started thinking about routing - maybe RoR is
supposed to route the request for the js file, but this is failing
somehow? However, I have found no information about this. I just have
some default routing set up in my route.rb file:
map.connect ‘:controller/:action/:id’
So my questions are:
-
Is it necessary to preclude the /javascripts/ path from going to the
dispatcher in order to be able to include the files there? -
If so, what am I doing wrong? Why is RewriteCond %{REQUEST_URI}
^/javascripts/(.*)$ [OR] not working? -
If not, am I supposed to set up some routing for this to work?
-
If I’m not supposed to set up any .htaccess precludes nor routing,
what could possibly be going wrong?