Hi,
I''d like to insert/append some default text into a text area after
clicking on an image button ''test.png'' in edit.rhtml:
<%= link_to image_tag("test.png"), url => { :action =>
:new_text } %>
Action:
# article_body is the textarea''s id.
def new_text
render :update do |page|
page.insert_html :bottom, :article_body, "text\n"
end
end
Not surprisingly insert_html doesn''t work properly in this innerHTML
context. But how it is possible to append text to existing one?
page[:article_body][:value] = "text"
e.g. overwrites the old content completely.
Do I need to use request.raw_post or reques.query_string in some way?
Best regards
Ingo
--
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 post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
When in doubt, drop to javascript:
page << "$(''article_body'').value +=
''blah''"
On Mar 26, 2:10 am, Ingo Paulsen
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi,
>
> I''d like to insert/append some default text into a text area after
> clicking on an image button ''test.png'' in edit.rhtml:
>
> <%= link_to image_tag("test.png"), url => { :action =>
:new_text } %>
>
> Action:
>
> # article_body is the textarea''s id.
>
> def new_text
> render :update do |page|
> page.insert_html :bottom, :article_body, "text\n"
> end
> end
>
> Not surprisingly insert_html doesn''t work properly in this
innerHTML
> context. But how it is possible to append text to existing one?
>
> page[:article_body][:value] = "text"
>
> e.g. overwrites the old content completely.
>
> Do I need to use request.raw_post or reques.query_string in some way?
>
> Best regards
> Ingo
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks for this Eden,
just wondering:
page << "$(''article_body'').value +=
''\n\\blah\n''"
with some extra newlines and a backslash works in a javascript function:
function insertText(obj,myText) {
//obj.value += myText;
$(''article_body'').value += ''\n\\blah\n''
}
but not within a RJS environment (only tabs for example):
render :update do |page|
page << "$(''article_body'').value +=
''\n\\blah\n''"
end
Any ideas?
Regards
Ingo
> When in doubt, drop to javascript:
>
> page << "$(''article_body'').value +=
''blah''"
>
> On Mar 26, 2:10 am, Ingo Paulsen
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
--
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 post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Thanks for this Eden,
>
> just wondering:
>
> page << "$(''article_body'').value +=
''\n\\blah\n''"
>
> with some extra newlines and a backslash works in a javascript function:
>
> function insertText(obj,myText) {
> //obj.value += myText;
> $(''article_body'').value +=
''\n\\blah\n''
>
> }
>
> but not within a RJS environment (only tabs for example):
>
> render :update do |page|
> page << "$(''article_body'').value +=
''\n\\blah\n''"
> end
>
> Any ideas?
>
> Regards
> Ingo
>
> > When in doubt, drop to javascript:
>
> > page << "$(''article_body'').value +=
''blah''"
>
> > On Mar 26, 2:10 am, Ingo Paulsen
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>-- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>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 -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---