I’m trying to code this anchor tag in Rails. It’s just a link to use
scriptaculous to “blind” open a div that I’ve got hidden by default.
Add comment
Also, how would Rails degrade this link if javascript was disabled? In
other words, how do I get it to display by default if javascript was
disabled? Or would I be responsible for that, not Rails?
Thanks for any help.
On 7 Apr 2008, at 16:12, Jl Smith wrote:
I’m trying to code this anchor tag in Rails. It’s just a link to use
scriptaculous to “blind” open a div that I’ve got hidden by default.
Add comment
link_to_function ‘Add Comment’, ‘your javascript here’
Also, how would Rails degrade this link if javascript was disabled?
In
other words, how do I get it to display by default if javascript was
disabled? Or would I be responsible for that, not Rails?
You would have to do that.
Fred
Thanks Fred. That worked great.
But as far as me allowing non-javascript users to see the form by
default, I was thinking I could just use javascript to set the “display:
none” styling. I tried that by doing this:
<%= javascript_tag
“window.document.getElementById(add_comment).style.display=none;”,
:defer => ‘defer’ -%>
but I get a javascript error “add_comment is not defined”. I know it’s
defined but am I implementing the javascript incorrectly? What’s the
“rails way” to do this? Put my javascript somewhere else, instead of at
the bottom of this particular view I’m in?
Thanks again.
On 7 Apr 2008, at 16:45, Jl Smith wrote:
:defer => ‘defer’ -%>
You needed to quote it (getElementById(‘add_comment’)). You can write
this more concisely if you’re using prototype: $(‘add_comment’).hide()
Fred
And btw, here’s the html for “add_comment”:
Add Comment
<%= render :partial => @comment = Comment.new, :locals => {
:button_name => 'Add comment' } -%>
Thanks again Fred…you’re the man. Prototype really cleaned that up.
And I guess I didn’t need to use the “defer” option…seems to work
without it?