A simple javascript alert not working

64 views
Skip to first unread message

Paul Bergstrom

unread,
May 31, 2013, 1:36:01 PM5/31/13
to rubyonra...@googlegroups.com
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.

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
May 31, 2013, 5:17:37 PM5/31/13
to rubyonra...@googlegroups.com
On 31 May 2013 18:36, Paul Bergstrom <li...@ruby-forum.com> 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

>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/25cb5ad9a7367a51c4821cadd1554cef%40ruby-forum.com?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Paul Bergstrom

unread,
Jun 1, 2013, 4:00:50 AM6/1/13
to rubyonra...@googlegroups.com
Colin Law wrote in post #1110840:
> On 31 May 2013 18:36, Paul Bergstrom <li...@ruby-forum.com> 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 Law

unread,
Jun 1, 2013, 4:09:52 AM6/1/13
to rubyonra...@googlegroups.com
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

Paul Bergstrom

unread,
Jun 1, 2013, 5:52:11 AM6/1/13
to rubyonra...@googlegroups.com
Colin Law wrote in post #1110879:
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?

Norbert Melzer

unread,
Jun 1, 2013, 6:11:01 AM6/1/13
to Rails Mailinglist

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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Colin Law

unread,
Jun 1, 2013, 6:35:54 AM6/1/13
to rubyonra...@googlegroups.com
On 1 June 2013 10:52, Paul Bergstrom <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1110879:
>> On 1 June 2013 09:00, Paul Bergstrom <li...@ruby-forum.com> 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?

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

Paul Bergstrom

unread,
Jun 1, 2013, 6:43:16 AM6/1/13
to rubyonra...@googlegroups.com
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?

Paul Bergstrom

unread,
Jun 1, 2013, 6:52:29 AM6/1/13
to rubyonra...@googlegroups.com
Colin Law wrote in post #1110893:
You don't need more information. Thanks for your help but don't look for
something I didn't ask. :-)

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

unread,
Jun 1, 2013, 6:56:31 AM6/1/13
to rubyonra...@googlegroups.com
On 1 June 2013 11:52, Paul Bergstrom <li...@ruby-forum.com> wrote:
> Colin Law wrote in post #1110893:
>> On 1 June 2013 10:52, Paul Bergstrom <li...@ruby-forum.com> 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. :-)
>
> 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 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.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4d56296fbe01e0b4ba7c4ebb95bfe87c%40ruby-forum.com?hl=en-US.

Norbert Melzer

unread,
Jun 1, 2013, 8:23:31 AM6/1/13
to Rails Mailinglist



2013/6/1 Paul Bergstrom <li...@ruby-forum.com>
Norbert Melzer 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. 

Paul Bergstrom

unread,
Jun 1, 2013, 10:15:11 AM6/1/13
to rubyonra...@googlegroups.com
Norbert Melzer wrote in post #1110905:
> 2013/6/1 Paul Bergstrom <li...@ruby-forum.com>

> 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. :-)
Reply all
Reply to author
Forward
0 new messages