bernat / best_in_place

A RESTful unobtrusive jQuery Inplace-Editor and a helper as a Rails Gem
http://blog.bernatfarrero.com/in-place-editing-with-javascript-jquery-and-rails-3/
1.2k stars 574 forks source link

display_as helper method: undefined method #564

Open d33pjs opened 7 years ago

d33pjs commented 7 years ago

Hello,

display_as doesnt seem to work in my case:

notes_controller.rb:

    respond_to :html, :json, :js
    def update
        @note = Note.find(params[:id])
        @note.update_attributes(params[:note].permit(:note))
        respond_with @project
    end

application_helper.rb:

    def markdown(text)
        [...]
        markdown.render(text).html_safe
    end

_note.html.erb:

    <%= best_in_place note, :note, :as => :textarea, :url => project_note_path(id: note.id, project_id: @project.id), display_as: markdown(note.note) %>

Errormessage:

undefined method `<p>markup note test content</p>
' for #<Note:0xb2edef0>

I also tried it with display_with and helper_options, but than, i get an argument exception.

I tought, its the same as in this example: http://stackoverflow.com/questions/22565409/how-to-pass-variables-to-a-best-in-place-display-as-custom-method

But its not working.

Thanks and Regards, Jens

etika commented 6 years ago

@bernat @Havoc85 facing same issue any solution for this???, i am also trying similar thing

In view
schedule.legs.each_with_index do |leg, index|
                  %tbody
                    %td= best_in_place schedule, :legs, as: :input,:display_as => location(schedule, index), url:  abc_fields_path(id:schedule.id),:value=>leg["location"]
In helper    
  def location(schedule, index)
        schedule.legs[index]["location"]
      end
Error
undefined method `ABC' for #<Class Name>

Where legs is a json field which is an array of hashes which iam iterating over it