# Passing Ajax.InPlaceEditor options

**URL:** <https://www.ruby-forum.com/t/passing-ajax-inplaceeditor-options/100956>\
**Category:** Rails\
**Created:** [August 2, 2006, 3:11am UTC](https://www.ruby-forum.com/t/passing-ajax-inplaceeditor-options/100956 "2006-08-02T03:11:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyleh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9a28c/32.png) [@kyleh](https://www.ruby-forum.com/u/kyleh)\
**Post date:** [August 2, 2006, 3:11am UTC](https://www.ruby-forum.com/t/passing-ajax-inplaceeditor-options/100956/1 "2006-08-02T03:11:35Z")

</div>

I’ve followed the instructions in the Rails Recipe #1 and have the  
in\_place\_editor\_field working but now I want to tweak how it looks and  
behaves. I’d like to be able to override the default yellow highlight  
color,  
which is done using the highlightcolor param according to the  
scriptaculous  
documentation (unless I’m missing something).

I’m new to Ruby and Rails so I’m hoping that I’m just missing something.

My view code looks like this:

\<%= in\_place\_editor\_field :platform, :name %\>

I’ve tried various forms of these options:

\<%= in\_place\_editor\_field :platform, :name, {}, { :highlightcolor =\>  
“#EAEAEA” } %\>  
\<%= in\_place\_editor\_field :platform, :name, {}, { “highlightcolor” =\>  
“#EAEAEA” } %\>  
\<%= in\_place\_editor\_field :platform, :name, {}, :in\_place\_editor\_options  
=\>  
{ :highlightcolor =\> “#EAEAEA” } %\>

None of those worked, no error and no difference in the Ruby generated  
javascript code.

Thanks in advance.

Kyle H.  
[www.kyleheon.com](http://www.kyleheon.com)

---

<div class="post-metadata">

**Author:** ![kyleh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9a28c/32.png) [@kyleh](https://www.ruby-forum.com/u/kyleh)\
**Post date:** [August 2, 2006, 3:24am UTC](https://www.ruby-forum.com/t/passing-ajax-inplaceeditor-options/100956/2 "2006-08-02T03:24:19Z")

</div>

> Kyle H. wrote:  
> I’ve followed the instructions in the Rails Recipe #1 and have the  
> in\_place\_editor\_field working but now I want to tweak how it looks and  
> behaves.

I’m going from memory here, but I don’t believe there are options baked  
into the in\_place\_editor methods that allow you to customize it to that  
degree.

However, in that same book (Rails Recipes) there’s another recipe that  
goes _into_ the JavaScript files where the inline editor is defined. The  
purpose of that recipe is to create a custom in\_place\_editor field for  
select lists. I’m sure while following along in that chapter you will  
find what you’re looking for.

- Daniel

---

<div class="post-metadata">

**Author:** ![kyleh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9a28c/32.png) [@kyleh](https://www.ruby-forum.com/u/kyleh)\
**Post date:** [August 3, 2006, 12:04pm UTC](https://www.ruby-forum.com/t/passing-ajax-inplaceeditor-options/100956/3 "2006-08-03T12:04:49Z")

</div>

Kyle H. wrote:

> \<%= in\_place\_editor\_field :platform, :name %\>
> 
> I’ve tried various forms of these options:
> 
> \<%= in\_place\_editor\_field :platform, :name, {}, { :highlightcolor =\>  
> “#EAEAEA” } %\>  
> \<%= in\_place\_editor\_field :platform, :name, {}, { “highlightcolor” =\>  
> “#EAEAEA” } %\>  
> \<%= in\_place\_editor\_field :platform, :name, {}, :in\_place\_editor\_options  
> =\> { :highlightcolor =\> “#EAEAEA” } %\>

Hi,

As another person noted; these aren’t supported by Rails yet. I actually  
did a quickie and just created my own in\_place\_editor\_field\_ext in my  
application\_helper. This is the full code adding support for _all_ the  
interesting InPlaceEditor-helpers. Hmm. Maybe I should submit this code  
to the core?

def in\_place\_editor\_ext(field\_id, options = { })  
function = “new Ajax.InPlaceEditor(”  
function \<\< "‘#{field\_id}’, "  
function \<\< “‘#{url\_for(options[:url])}’”

js\_options = {}  
js\_options[‘okButton’] = options[:ok\_button] if options[:ok\_button]  
js\_options[‘cancelLink’] = options[:cancel\_link] if  
options[:cancel\_link]  
js\_options[‘savingText’] = %(‘#{options[:saving\_text]}’) if  
options[:saving\_text]  
js\_options[‘clickToEditText’] = %(‘#{options[:click\_to\_edit\_text]}’)  
if options[:click\_to\_edit\_text]  
js\_options[‘highlightcolor’] = %(‘#{options[:highlight\_color]}’) if  
options[:highlight\_color]  
js\_options[‘highlightendcolor’] =  
%(‘#{options[:highlight\_end\_color]}’) if options[:highlight\_end\_color]

js\_options[‘cancelText’] = %(‘#{options[:cancel\_text]}’) if  
options[:cancel\_text]  
js\_options[‘okText’] = %(‘#{options[:save\_text]}’) if  
options[:save\_text]  
js\_options[‘loadingText’] = %(‘#{options[:loading\_text]}’) if  
options[:loading\_text]  
js\_options[‘rows’] = options[:rows] if options[:rows]  
js\_options[‘cols’] = options[:cols] if options[:cols]  
js\_options[‘size’] = options[:size] if options[:size]  
js\_options[‘externalControl’] = “‘#{options[:external\_control]}’” if  
options[:external\_control]  
js\_options[‘loadTextURL’] = “‘#{url\_for(options[:load\_text\_url])}’”  
if options[:load\_text\_url]  
js\_options[‘ajaxOptions’] = options[:options] if options[:options]  
js\_options[‘evalScripts’] = options[:script] if options[:script]  
js\_options[‘callback’] = “function(form) { return #{options[:with]}  
}” if options[:with]  
function \<\< (', ’ + options\_for\_javascript(js\_options)) unless  
js\_options.empty?

function \<\< ‘)’

javascript\_tag(function)  
end

def in\_place\_editor\_field\_ext(object, method, tag\_options = {},  
in\_place\_editor\_options = {})  
tag = ::ActionView::Helpers::InstanceTag.new(object, method, self)  
tag\_options = {:tag =\> “span”, :id =\>  
“#{object}_#{method}_#{tag.object.id}_in\_place\_editor", :class =\>  
“in\_place\_editor\_field”}.merge!(tag\_options)  
in\_place\_editor\_options[:url] = in\_place\_editor\_options[:url] ||  
url\_for({ :action =\> "set_#{object}\_#{method}”, :id =\> tag.object.id })  
tag.to\_content\_tag(tag\_options.delete(:tag), tag\_options) +  
in\_place\_editor\_ext(tag\_options[:id], in\_place\_editor\_options)  
end

–  
Ola B. ([http://ola-bini.blogspot.com](http://ola-bini.blogspot.com))  
JvYAML, RbYAML, JRuby and Jatha contributor  
System Developer, Karolinska Institutet ([http://www.ki.se](http://www.ki.se))  
OLogix Consulting ([http://www.ologix.com](http://www.ologix.com))

“Yields falsehood when quined” yields falsehood when quined.
