Thanks Frederick!, the long answer is what I needed :), very useful
indeed.
I also tried to write a RJS partial embedding javascript, then render
it within the view, but
I only got an HTML page not rendered.
In the end, what I want to do is toggle a div, and replace an element
HTML with some content when the div is hidden, and with another
content when the div is showed:
Initially, the div is hidden with style=display:none
“show_details”) do |page|
page.visual_effect :toggle_blind, :new_item_details
if page[:new_item_details].visible
page[:show_details].replace_html “Hide details”
else
page[:show_details].replace_html “Show details”
end
end %>
so when user clicks the link, text is changed from ‘Show details’ to
‘Hide details’, but I never get to change ‘Hide details’ to ‘Show
details’, it seems that ‘new_item_details’ div
is always visible when it isn’t.
On 25 Aug 2008, at 18:44, Eduardo Yáñez Parareda wrote:
page << “else”
text, but no errors. What am i doing wrong?
You’re creating syntactically invalid javascript: the curly brace
you’re opening on the if line is never closed.
but the page is not rendered fine. So I’ve chosen an easy solution,
I’ve written the function into application.js as javascript, and all
works fine now.
Thank you Frederick for your help!
but the page is not rendered fine. So I’ve chosen an easy solution,
I’ve written the function into application.js as javascript, and all
works fine now.
Hard to say without seeing what was inserted into the page, but if the
javascript that is created included " (which it probably does) then
crazy stuff would happen. Wrapping the render :partial in a
javascript_tag would probably have helped.
Yes, may be that double quotes broke the page. Anyway it’s more clear
to have javascript in a javascript file :), but I was trying to do it
with RJS because
I’m not used to use it.
On 25 Aug 2008, at 23:13, Eduardo Yáñez Parareda wrote:
Although it already works fine into application.js, I’ve tried one
last attempt with RJS. My partial now is:
Forgot to say - I think this is absolutely the right way to go -
there’s no point trying to shoehorn stuff into rjs which is more
easily written as just plain javascript. But it’s always good to
understand why something didn’t work.
but still doesn’t render fine. Moreover, if I leave the partial empty
(nothing into the RJS), it doesn’t work!!!
because of the try/catch stuff that’s still there even if the partial
is empty.
The javascript_tag helper will wrap this in a CDATA section which
should make everything happy.
Fred
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.