# In\_place\_edit\_for - non clickable when value is blank

**URL:** <https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506>\
**Category:** Rails\
**Created:** [January 12, 2009, 1:03pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506 "2009-01-12T13:03:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [January 12, 2009, 1:03pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506/1 "2009-01-12T13:03:27Z")

</div>

A pretty common problem but I haven’t found a solution that works.

I’m using in\_place\_editor\_field in my view and all works well when there  
is data but when the field is blank, I am unable to edit as there is no  
clickable area. Is there a simple and working solution out there I could  
make use of?

Thanks

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [January 12, 2009, 1:06pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506/2 "2009-01-12T13:06:58Z")

</div>

check this out:

> **[Aku Aku](https://www.akuaku.org/)**
>
> v.. To move a tall, flat bottomed object (such as a bookshelf) by swiveling it alternatively on its corners in a "walking" fashion. \[After the book by Thor Heyerdahl theorizing the statues of Easter Island were moved in this fashion.\] source:...

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [January 12, 2009, 1:10pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506/3 "2009-01-12T13:10:45Z")

</div>

MaD wrote:

> check this out:  
> [Aku Aku](http://www.akuaku.org/archives/2006/08/in_place_editor_1.shtml)

Thanks for the response

Sadly I’ve already tried this and failed to get it to work, even after  
working my way through the comments and applying the recommended  
changes. Even the CSS solution in the most recent comment failed to work  
as IE6 does not support generated content.

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [January 12, 2009, 1:41pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506/4 "2009-01-12T13:41:46Z")

</div>

maybe write something similar yourself (= fix that script with updated  
code from the plugin) or try to set your default-values to something  
like “…”.

what’s your error trace?

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [January 12, 2009, 1:56pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506/5 "2009-01-12T13:56:28Z")

</div>

try overriding it like that (i just took the code from github and  
added an if-clause):

def in\_place\_edit\_for(object, attribute, options = {})  
define\_method(“set\_#{object}\_#{attribute}”) do  
@item = object.to\_s.camelize.constantize.find(params[:id])  
# adjust the following if-clause to your needs  
if params[:value].blank?  
params[:value] = “…”  
end  
@item.update\_attribute(attribute, params[:value])  
render :text =\> @item.send(attribute).to\_s  
end  
end

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [October 2, 2009, 7:26pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506/6 "2009-10-02T19:26:27Z")

</div>

Don’t know if you found a solution to this but here’s mine: In my  
database definition I make the default value a ‘-’ (or some other  
non-meaningful value) for a varchar field, or 0 for an int field. My  
migration to modify existing columns looks like this:

`
class ChangeDefaults < ActiveRecord::Migration
  def self.up
    change_column :nodes, :sysName, :string, :null => false, :default 
=> '-'
    change_column :nodes, :ip, :string, :null => false, :default 
=> '-'
    change_column :ports, :vlan, :integer, :null => false, :default => 
0
  end
end
`

With this you don’t need to modify any plugin code.

Hope this helps.

James R. wrote:

> A pretty common problem but I haven’t found a solution that works.
> 
> I’m using in\_place\_editor\_field in my view and all works well when there  
> is data but when the field is blank, I am unable to edit as there is no  
> clickable area. Is there a simple and working solution out there I could  
> make use of?
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [January 15, 2009, 1:57pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506/7 "2009-01-15T13:57:03Z")

</div>

MaD wrote:

> try overriding it like that (i just took the code from github and  
> added an if-clause):
> 
> def in\_place\_edit\_for(object, attribute, options = {})  
> define\_method(“set\_#{object}\_#{attribute}”) do  
> @item = object.to\_s.camelize.constantize.find(params[:id])  
> # adjust the following if-clause to your needs  
> if params[:value].blank?  
> params[:value] = “…”  
> end  
> @item.update\_attribute(attribute, params[:value])  
> render :text =\> @item.send(attribute).to\_s  
> end  
> end

Thanks for the response, can you tell me how I’d use the above code?  
I’ve experimented by creating a file called ‘extensions.rb’ within the  
lib folder, the doing: require ‘extensions’ within environment rb. I’ve  
tried the method on it’s own, followed by placing it within a class  
wrapper and keep getting errors for ‘wrong number of arguments’. My  
extensions.rb currently looks like this:

[code]class Extensions

ActionController::Macros::InPlaceEditing::ClassMethods.class\_eval do  
def in\_place\_edit\_for(object, attribute)  
define\_method(“set\_#{object}\_#{attribute}”) do  
@item = object.to\_s.camelize.constantize.find(params[:id])  
# adjust the following if-clause to your needs  
if params[:value].blank?  
params[:value] = “…”  
end  
@item.update\_attribute(attribute, params[:value])  
render :text =\> @item.send(attribute).to\_s  
end  
end  
end

end[/code]

Thanks for any help

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [October 2, 2009, 8:47pm UTC](https://www.ruby-forum.com/t/in-place-edit-for-non-clickable-when-value-is-blank/157506/8 "2009-10-02T20:47:06Z")

</div>

Colin Wu wrote:

> Don’t know if you found a solution to this but here’s mine: In my  
> database definition I make the default value a ‘-’ (or some other  
> non-meaningful value) for a varchar field, or 0 for an int field.

Terrible idea. This is meaningless default data that is only neede for  
display reasons, and as such has no place in the DB.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
