Forum: Ruby on Rails in_place_edit_for - non clickable when value is blank

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5e5594ea179b8afa9543e4adbc3b7e68?d=identicon&s=25 James Riley (jrileyness2)
on 2009-01-12 13:03
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
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-01-12 13:06
(Received via mailing list)
5e5594ea179b8afa9543e4adbc3b7e68?d=identicon&s=25 James Riley (jrileyness2)
on 2009-01-12 13:10
MaD wrote:
> check this out:
> http://www.akuaku.org/archives/2006/08/in_place_ed...

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.
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-01-12 13:41
(Received via mailing list)
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?
80e4cb97cae5c8d745f72337d93fd8f2?d=identicon&s=25 MaD (Guest)
on 2009-01-12 13:56
(Received via mailing list)
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
5e5594ea179b8afa9543e4adbc3b7e68?d=identicon&s=25 James Riley (jrileyness2)
on 2009-01-15 13:57
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
C9924d40ef0292f06a45939d1b2a20b4?d=identicon&s=25 Colin Wu (cwu)
on 2009-10-02 19:26
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:

<code>
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
</code>

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

Hope this helps.

James Riley 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
Dd2d775dea75b381edb1bbf0600a0907?d=identicon&s=25 Marnen Laibow-Koser (marnen)
on 2009-10-02 20:47
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
marnen@marnen.org
This topic is locked and can not be replied to.