Dav Yaginuma;
Husband, Father, Hacker, Thinker, Maker;
San Francisco.

Twitter Updates

    follow me on Twitter

    Dav's bookshelf: read

    Star Wars: Han Solo
    liked it
    tagged: graphic-novels
    See you at the 7: Stories From the Bay Area's Last Original Mile House
    it was amazing
    There's a little dive pub (turns out actually not a dive anymore) I'd been meaning to go to for years, and finally stopped by a couple of weeks back. I love checking out the old San Francisco spots that persist through the decades and ha...
    The Undefeated
    really liked it
    Wonderful poem and great illustrations.

    goodreads.com
    Blog powered by Typepad

    « srl | Main | login sugar for the salted hash login generator »

    Comments

    Feed You can follow this conversation by subscribing to the comment feed for this post.

    Matteo Vaccari

    It works perfectly. You should submit this to the dev team!

    jfoxny

    This solution worked well, sans one issue. When using in_place_edit_for any field whose value was cleared by the edit would no longer be editable. So, I cracked open the code and made use of the (unused) options parameter to pass in a value to be used when the update results in an empty value. The new parameter is :empty_text. Here's the code:


    ActionController::Macros::InPlaceEditing::ClassMethods.class_eval do
    def in_place_edit_for(object, attribute, options = {})
    define_method("set_#{object}_#{attribute}") do
    @item = object.to_s.camelize.constantize.find(params[:id])
    @item.update_attribute(attribute, params[:value])
    display_value = params[:value].empty? && options[:empty_text] ? options[:empty_text] : @item.send(attribute)
    render :text => display_value
    end
    end
    end

    Julian Guppy

    I am also trying to do this in_place_edit and have also found that after it is blanked and updated the field becomes unclickable. I tried jfoxny code but couldn't get it to work. jfoxny can you post an example of it being used... or where you placed this snippet also inside extensions.rb?

    Julian (not a noob, but not an expert either)

    rjb

    Hey Julian, I am sure you figured this out, but for others, like myself, who did not "get" what to do with jfoxny's addition right off the bat, all you need to do is add the :empty_text parameter to the in_place_edit_for call in your controller...
    class UsersController '...'
    end

    His snippet also lives within the extension class. I hope this helps... only a month late :)

    deezzer

    this code no longer works with rails 1.2.2...does anyone have a patch?

    Cussen

    For 1.2.2


    ActionView::Helpers::InstanceTag.class_eval do
    attr_writer :nil_content_replacement

    def value(object)
    unless object.nil?
    v = object.send(@method_name)
    if @nil_content_replacement.nil?
    return v
    else
    (v.nil? || v.to_s.strip=='') ? @nil_content_replacement : v
    end
    end
    end
    end

    mkezys

    Does not work for me, i get following error:

    wrong number of arguments (1 for 0)
    Extracted source (around line #87):
    ...
    87:
    ...

    #{RAILS_ROOT}/lib/extensions.rb:16:in `in_place_editor_field'

    in extensions.rb i have at this line:

    tag.to_content_tag(tag_options.delete(:tag), tag_options) +

    Same if I change this line to:
    tag.to_content_tag(tag_options.delete(:tag), tag_options) + in_place_editor(tag_options[:id], in_place_editor_options)
    or
    tag.to_content_tag(tag_options.delete(:tag), tag_options)

    What could be the problem?

    joe

    mkezys: I had the same problem. Turns out the implementation of value() in the post is incorrect. It should be

    def value(object)

    not

    def value

    Cussen's comment above has it defined correctly. That's why you get the "wrong number of args" error

    doppler

    Nothing suggested in this thread worked for me (Rails 2.0.2) but after much hair-pulling, I had an AHA! moment. I put a bit of CSS at the top of my template:


    .in_place_editor_field:after {
    content: url(/images/edit_entry_12.png)
    }


    Basically, CSS dynamically inserts the a small image into the , giving you something to click on when the is otherwise empty. You can also use "content:'some text'" instead of an image, but that looks ugly.

    Verify your Comment

    Previewing your Comment

    This is only a preview. Your comment has not yet been posted.

    Working...
    Your comment could not be posted. Error type:
    Your comment has been posted. Post another comment

    The letters and numbers you entered did not match the image. Please try again.

    As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

    Having trouble reading this image? View an alternate.

    Working...

    Post a comment

    Your Information

    (Name is required. Email address will not be displayed with the comment.)

    lenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();