When in doubt, drop to javascript:
page << "$('article_body').value += 'blah'"
When in doubt, drop to javascript:
page << "$('article_body').value += 'blah'"
Where is your RJS being loaded up?
Your escaping is a off with the newlines, so that could be the issue. When you use #<<, you'll be dumping a string directly to javascript, and ruby's quoting is getting in the way, so "$('article_body').value += '\n\\blah\n'" would be sent to your browser as:
"$('article_body').value += ' \blah '
Instead you should escape the newlines. Also, you'll need to double escape the \\ before the b, because '\b' will get interpreted in javascript as a backspace character: "$('article_body').value += '\\n\\ \\blah\\n'". Or you can use ruby single quotes and heredocs to make things look nicer although you won't be able to insert variables into the string block.
page << <<-'end' $('article_body').value += '\n\\blah\n'; end
Ingo Paulsen wrote:
Thanks again Eden,
this was helpful for me. I didn't get the double backslash (escape) point yesterday.
Regards Ingo
Where is your RJS being loaded up?
Your escaping is a off with the newlines, so that could be the issue. When you use #<<, you'll be dumping a string directly to javascript, and ruby's quoting is getting in the way, so "$('article_body').value += '\n\\blah\n'" would be sent to your browser as:
"$('article_body').value += ' \blah '
Instead you should escape the newlines. Also, you'll need to double escape the \\ before the b, because '\b' will get interpreted in javascript as a backspace character: "$('article_body').value += '\\n\\ \\blah\\n'". Or you can use ruby single quotes and heredocs to make things look nicer although you won't be able to insert variables into the string block.
page << <<-'end' $('article_body').value += '\n\\blah\n'; end
On Mar 26, 5:23 am, Ingo Paulsen <rails-mailing-l...@andreas-s.net>
Hi,
This helps for me but I have 1 doubt
def add_text_link(name) link_to_function name do |page| begin page << <<-'end' $('text_area').value += "\n Hello world" ; end end
I added above code in the RJS, this works but if I need to use the name parameter that is passed in how do I do it?
I tried #{name} but no luck...
Thanks, Sudhindra