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.

On 31 May 2013 18:36, Paul B. [email protected] wrote:

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 L. wrote in post #1110840:

On 31 May 2013 18:36, Paul B. [email protected] wrote:

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

Not sure how I can explain it better. It’s a very simple example.

When going with the browser to an action with a corresponding *.js.erb
file should the JavaScript in that file run, like alert(“hello”)? Or is
that old rjs?

Colin L. wrote in post #1110879:

On 1 June 2013 09:00, Paul B. [email protected] wrote:

Not sure how I can explain it better. It’s a very simple example.

When going with the browser to an action with a corresponding *.js.erb
file should the JavaScript in that file run, like alert(“hello”)? Or is
that old rjs?

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

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

Should this very very basic example of UJS work? Do I need to add
something with format.js {}? In routes?

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.
Am 01.06.2013 11:52 schrieb “Paul B.” [email protected]:

On 1 June 2013 10:52, Paul B. [email protected] wrote:

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

Norbert M. 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?

Am 01.06.2013 11:52 schrieb “Paul B.” [email protected]:

On 1 June 2013 09:00, Paul B. [email protected] wrote:

Not sure how I can explain it better. It’s a very simple example.

When going with the browser to an action with a corresponding *.js.erb
file should the JavaScript in that file run, like alert(“hello”)? Or is
that old rjs?

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 L. wrote in post #1110893:

On 1 June 2013 10:52, Paul B. [email protected] wrote:

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.

2013/6/1 Paul B. [email protected]

Norbert M. wrote in post #1110888:

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?

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.

On 1 June 2013 11:52, Paul B. [email protected] wrote:

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

Norbert M. wrote in post #1110905:

2013/6/1 Paul B. [email protected]

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.

I think I understand it better now. My example will only work if it’s an
ajax call, specifically pointing to a js script? Is that right.

So that would mean a NO to my question. An alert(hello"") will not run,
in a file “index.js.erb”, by simply going to the corresponding action
“index”, the HTML file?

No need for log file. :slight_smile: