In_place_edit_for - non clickable when value is blank

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

check this out:

MaD wrote:

check this out:
Aku Aku

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.

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?

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

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

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

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
[email protected]