Javascript trouble

I’m trying to understand Javascript in Rails.

I have a controller called logo. In there I have a method called new. In
views I have a folder called logo, with logo.rthml in layouts with <%=
javascript_include_tag :defaults %> in that same file. I have a file
called new.rhtml in the folder logo. In the same folder, logo, I have a
new.rjs. Is that the right setup? I can’t get this to work:

page.alert(“hello”)

Can Rails actually deal with Javascript? I can’t get it working. Very
frustrating. Shouldn’t the above setup be correct? Once again, the
documentation really sucks (sorry).

Anyone? Is Javascript this shaky in Rails? I can’t understand why it
doesn’t work.

Problem #1: You’re assuming that Rails does Javascript. Javascript can
only
be run by a browser, Rails just has lots of helpers for printing out
useful
Javascript to the page.

Problem #2: What exactly are you trying to do? RJS is mostly used with
AJAX
calls (aka you are creating script that gets executed when Ajax.request
is
called).

And actually, the documentation doesn’t “really suck”, you’re trying to
use
a feature without understanding how or what it does.

Jason

Jason R. wrote:

Problem #1: You’re assuming that Rails does Javascript. Javascript can
only
be run by a browser, Rails just has lots of helpers for printing out
useful
Javascript to the page.

Problem #2: What exactly are you trying to do? RJS is mostly used with
AJAX
calls (aka you are creating script that gets executed when Ajax.request
is
called).

I mean the “implementation” in Rails of Javascript. Of course it’s run
by the browser.

I’m just trying a simple alert() onload, as described above. Though I
discovered that this works <%= link_to_function “Greeting”,
“alert(‘Hello world!’)” %> in the view-file. So obviously Javascript is
ok, and I’m doing something wrong.

And actually, the documentation doesn’t “really suck”, you’re trying to use
a feature without understanding how or what it does.

Exactly. That’s why it’s good to have a good manual. I don’t think I’m
the first to have this view about Rails manual.

Jason R. wrote:

If you’re serious about learning the ins and outs of Rails, go to your
local
bookstore and pick up Agile Web D. with Rails. And be sure
you’ve
looked through the information here: http://rubyonrails.com/docs. There
is
an ever growing amount of Rails tutorials and information.

There’s not much else I can say here. We are happy to answer specific
questions or comments on using Rails. The reason what you are trying to
do
here doesn’t work touches on the basis of how Rails itself functions.
Sorry
I can’t be of any more help; please read through this information, it
should
answer your questions.

Jason

Yes, I’m serious. :slight_smile:

I already got Agile Web D. with Rails. I’ll take a look at it
again regarding RJS. But it’s rather massive.

If the docs where to be like php’s then it would be much easier. I mean,
Ruby in itself is easy understand. There are different ways of writing
and explaining things.

Ugh. I remember how much I hated PHP’s online docs. I’ll take the Rails
API
site over that anyday.</cents count=“two”>

RSL

Russell N. wrote:

Ugh. I remember how much I hated PHP’s online docs. I’ll take the Rails
API
site over that anyday.</cents count=“two”>

RSL

We see things differently then. I think the manual for php is something
for Rails to be inspired by. It’s linear and well designed in terms of
what it’s supposed to communicate, and the examples are good and easy to
spot (and not in “snippets”). The comments by users are excellent.

Take link_to_function for example. How do I find information on hiding a
layer in the manual?

On 3/14/07, PÃ¥l Bergström [email protected] wrote:

for Rails to be inspired by. It’s linear and well designed in terms of
what it’s supposed to communicate, and the examples are good and easy to
spot (and not in “snippets”). The comments by users are excellent.

Take link_to_function for example. How do I find information on hiding a
layer in the manual?

Um, what do you mean by “hiding a layer”?

Jason

Jason R. wrote:

On 3/14/07, PÃ¥l Bergström [email protected] wrote:

for Rails to be inspired by. It’s linear and well designed in terms of
what it’s supposed to communicate, and the examples are good and easy to
spot (and not in “snippets”). The comments by users are excellent.

Take link_to_function for example. How do I find information on hiding a
layer in the manual?

Um, what do you mean by “hiding a layer”?

Jason

document.getElementById(‘layer1’).style.display = ‘none’

I found it. On http://www.prototypejs.org/ of course. But that could
have been better and more clearly explained in rails api. Btw,
prototypejs.org is a really beautiful manual.

If you’re looking for documentation about Prototype’s methods then of
course the Rails docs are gonna suck. BTW, there’s no documentation
about
CSS selectors, or HTML frames, or JS function definitions either. :confused: I
guess
Rails sucks because it isn’t a one-stop shop for all your web
application
needs like PHP is. :confused:

RSL

Russell N. wrote:
one-stop shop for all your web

application
needs like PHP is. :confused:

RSL

That would be something :slight_smile:

Unfortunately that’s not the case with php either. Seriously, I don’t
mean the Rails API should explain Javascript. But as there is a
framework for dealing with Javascript it has to be included. And it is.
The problem is how it’s presented. It took my slow non-programmers brain
a while to figure out, that I had to go somewhere else to find more
info.

Even if I sounded sulky when complaining about the docs I’m actually
very happy to have found Rails. I’m not a programmer from start, but a
designer and nowadays self learned in html, css, javascript, php and
lasso, among other things. The basic in Rails, Ruby, has been by far the
easiest to get into. But Rails as a framework has been the most
difficult.

If you’re serious about learning the ins and outs of Rails, go to your
local
bookstore and pick up Agile Web D. with Rails. And be sure
you’ve
looked through the information here: http://rubyonrails.com/docs. There
is
an ever growing amount of Rails tutorials and information.

There’s not much else I can say here. We are happy to answer specific
questions or comments on using Rails. The reason what you are trying to
do
here doesn’t work touches on the basis of how Rails itself functions.
Sorry
I can’t be of any more help; please read through this information, it
should
answer your questions.

Jason

BTW you would hide the “layer” (or do you mean div) like this

<%=link_to_function(“Hide my Layer”, nil , :onclick =>
“Element.hide(‘layer1’)” )%>

On 3/15/07, PÃ¥l Bergström [email protected] wrote:

lasso, among other things. The basic in Rails, Ruby, has been by far the
easiest to get into. But Rails as a framework has been the most
difficult.

I see your point, but for sake of argument, our side of the story is
that
Rails is built to make web programming easier, not design. Rails is
built to
take care of the crap that goes into most web programming (propagated
mostly
by PHP) and to make the process enjoyable. Rails assumes that you know
HTML,
that you know web technologies and that you know the basics of
programming
itself. It is not a part of Rails, nor should it be, to offer tutorials
or
information on Javascript, as there is plenty of that on the web
already.

The documentation is sufficient in explaining what the Javascript
helpers
give you, even to the point of sending you off to Script.taculo.us for
the
documentation of the Javascript library itself. As a library
developer’s
point of view, if one had to package up documentation for every bit and
piece used in the library, it would be an ungodly huge bloat of
documentation text that would quickly be out of date and littering the
web
with bad copies of said documentation, making everyone’s lives more
difficult.

Rails is a change in web development thinking. For someone who’s been
with
PHP for a long time, it’s understandable if they have a hard time
switching,
but the time spent is more than worth it.

Again, we are more than happy to answer specific questions about Rails.
If
you want to know how certain other parts work (Javascript, etc), we can
help
by pointing you to good documentation.

That’s pretty much the developer’s side of the story.

Jason

Steven Albarracin wrote:

BTW you would hide the “layer” (or do you mean div) like this

<%=link_to_function(“Hide my Layer”, nil , :onclick =>
“Element.hide(‘layer1’)” )%>

I got that know, thanks. Now that I know where to look. My original
question was different. I basically was trying to do an alert() onload,
or onparse. That I haven’t figured out yet.

Layer is an old and common way of describing a div, yes. But you can
hide anything.

Jason R. wrote:

On 3/15/07, PÃ¥l Bergström [email protected] wrote:

Rails is a change in web development thinking. For someone who’s been
with
PHP for a long time, it’s understandable if they have a hard time
switching,
but the time spent is more than worth it.

Again, we are more than happy to answer specific questions about Rails.
If
you want to know how certain other parts work (Javascript, etc), we can
help
by pointing you to good documentation.

That’s pretty much the developer’s side of the story.

Jason

I hear you. I know Javascript and the rest. I don’t think you get my
point.

Jason R. wrote:

Though technically if you’re using Prototype, you can simply do:

Element.hide(‘layer1’);

As for your onload question, what’s wrong with just doing ?

Or if you have a layout and view files:

layout.rhtml:

>

some_action.rhtml

<% content_for(:body_tag) do %>
onload=“javascript stuff”
<% end %>

Jason

I’ve understood that’s the way to do it. I was trying to learn the
basics of how Javascript is implemented and wanted to try a simple
alert() onload – or onparse. Thanks for the suggestion. I’ll try it.

Though technically if you’re using Prototype, you can simply do:

Element.hide(‘layer1’);

As for your onload question, what’s wrong with just doing ?

Or if you have a layout and view files:

layout.rhtml:

>

some_action.rhtml

<% content_for(:body_tag) do %>
onload=“javascript stuff”
<% end %>

Jason