A simple javascript alert not working

If I have a file in view /test called index.js.erb and in it a simple
alert("hello") shouldn't that run when I go to /test/index? It doesn't.

If I have a file in view /test called index.js.erb and in it a simple
alert("hello") shouldn't that run when I go to /test/index? It doesn't.

I think you will have to give us a bit more detail on exactly what you
have done. First have a look at the Rails Guide on Debugging to see
ways that you can debug your code to work out what is going wrong.

Colin

Colin Law wrote in post #1110840:

Look in development.log to see what is happening. Look at the source
in the browser to see what is being sent to the browser.

Colin

Colin Law wrote in post #1110879:

Have you a route to a corresponding controller in general? Have you a controller? Does this controller work when you try to deliver an HTML view?
Oh, and when you want to have a js response, then you must use /test/index.js, without the extension given rails will try to deliver HTML (if you haven’t configured it to do something else). Do you get an error message in server logs or browser when you try to access your ressource? Which one?

Answer this questions as exactly as possible or we can’t help.

No idea what you mean by "doesn't seem to load". What do you see in
the log file? It is very difficult to help if you won't give us any
information.

Colin

Norbert Melzer wrote in post #1110888:

Have you a route to a corresponding controller in general? Have you a
controller? Does this controller work when you try to deliver an HTML
view?

Yes.

Oh, and when you want to have a js response, then you must use
/test/index.js, without the extension given rails will try to deliver
HTML

I know. You mean index.js.erb?

(if you haven't configured it to do something else). Do you get an error
message in server logs or browser when you try to access your ressource?
Which one?

No error messages.

Answer this questions as exactly as possible or we can't help.

Thank you for your help. Should this basic example work, onload? Or
should I skip extra js-files?

Colin Law wrote in post #1110893:

in the browser to see what is being sent to the browser.

Colin

Doesn't seem to load. This should be so incredible simple. Why doesn't
it work? What have I missed?

No idea what you mean by "doesn't seem to load". What do you see in
the log file? It is very difficult to help if you won't give us any
information.

Colin

You don't need more information. Thanks for your help but don't look for
something I didn't ask. :slight_smile:

The log file seems to be ok. Not sure what to look for. No error
messages when loading the file. That's all I can say.

I think it's better if you could verify that this normally should work.
That was my intention when asking the question. It would be a great
help.

Colin Law wrote in post #1110893:

in the browser to see what is being sent to the browser.

Colin

Doesn't seem to load. This should be so incredible simple. Why doesn't
it work? What have I missed?

No idea what you mean by "doesn't seem to load". What do you see in
the log file? It is very difficult to help if you won't give us any
information.

Colin

You don't need more information. Thanks for your help but don't look for
something I didn't ask. :slight_smile:

The log file seems to be ok. Not sure what to look for. No error
messages when loading the file. That's all I can say.

Just show us the log please. That will enable us to check that what
you think is happening is happening.

Colin

I mean, if your js-file is /app/views/test/index.js.erb AND your controller
is /app/controllers/test_controller.rb AND you have route setup to the
index action, then you have to point your browser to "
http://localhost:3000/test/index.js". This way you should see the content
of your index.js.erb. If you can't see it, there is something going wrong.

And if there is something going wrong you need to provide that pieces of
further information that is Colin asking you since the start of the thread.

Norbert Melzer wrote in post #1110905: