Adam Akhtar
2009-Feb-19 12:47 UTC
using #{} with instance variables inside prototypes $$()
I want to do something like this in a link_to_remote call in a view :before => ''$$("tr#task_#{completed_task.id} > td.task-title-cell").update("Reactivating")'' but the number of '' and " in the string are not allowing my #{completed...} to work. Its just being read as characters and not as a request to insert the value of the contained variable. How do i get round this and are there any tips for this? people must be using #{} within their prototype code a lot and it must look messy. is there a cleaner way? -- 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 -~----------~----~----~----~------~----~------~--~---
:before => "$$(''tr#task_#{completed_task.id} > td.task-title- cell'').update(''Reactivating'')" should do the trick. Also you probably need to add a .first() after your $$() selector, since it always returns an array as far as i know. As for your question regarding style, I think there isn''t really a better alternative and also I don''t think it looks too messy ... . if your selector gets really long and ugly you could assign it to a variable first, like: selector = "tr#task_#{completed_task.id} > td.task-title-cell" and then: :before => "$$(''#{selector}'').first().update(''Reactivating'')" On Feb 19, 1:47 pm, Adam Akhtar <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I want to do something like this in a link_to_remote call in a view > > :before => ''$$("tr#task_#{completed_task.id} > > td.task-title-cell").update("Reactivating")'' > > but the number of '' and " in the string are not allowing my > #{completed...} to work. Its just being read as characters and not as a > request to insert the value of the contained variable. > > How do i get round this and are there any tips for this? people must be > using #{} within their prototype code a lot and it must look messy. is > there a cleaner way? > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
your outermost quote is a single one ( '' ). that way rails won''t insert the value of your variable. you could simply try to swap single and double quotes. another way would be to introduce additional variables with substrings or just form your string with + example: array = ["big", "little"] substring = array[1] string = "my " + substring + " string is actually quite #{array[0]}" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---