views:

72

answers:

1

I need to send a class name with my observe_field call so I can update the correct text_field (there are multiples on the same page)

<%= observe_field  "songlists_" + section.id.to_s + "_song_name",
  :frequency => 0.5, :url => { :controller => :songlists, :action =>
  :get_artist }, :update => text_class , 
:with => "'song_name=' +encodeURIComponent(value)+'&songlists_classname='+ xxxxxxxx"  %>

Is there a way of inserting a ruby variable into the :with statement where 'xxxxxxxx' is displayed above?

Or any other way?

+1  A: 

Sure, why not? You're just passing a string to :with, so insert a variable into like you would any other string, e.g. "...&songlists_classname=#{your_variable}":

<%= observe_field "songlists_#{section.id}_song_name",
                  :frequency => 0.5,
                  :url => { :controller => :songlists, :action => :get_artist },
                  :update => text_class,
                  :with => "'song_name=' + encodeURIComponent(value) + '&songlists_classname=#{your_variable}'"  %>
Jordan
thanks, thought I'd tried every every combination of that, must of had my ' in the wrong place
Nick
Yeah, it can be tricky when you're nesting JavaScript strings inside Ruby strings. Don't forget to accept my answer if it worked for you.
Jordan