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 571 forks source link

line breaks in textareas #62

Closed brianmaissy closed 12 years ago

brianmaissy commented 12 years ago

This is a feature request.

When using a textarea, the developer often intends for the field to contain line breaks. Best_in_place doesn't display newlines in textareas as html <br> tags. It would be really convenient if it did by default, or had an option to.

I was able to implement a workaround with a display_as, but there are two problems with it: 1) During the time between sending the ajax request and receiving the response, it temporarily is displayed without the breaks, and then switches over. This is a little ugly. 2) It's a rather complicated workaround for a really common task.

Let me know if this is already possible and I just missed it.

rogercampos commented 12 years ago

Hi, thanks for your comments. I think it's usually best to let the developer handle how to display things and not give anything done by default. As you say, it can be done using the 'dispolay_as' feature, even though I may agree with you that this can be a little hard to do for a new rails developer. Maybe a better docs or a wiki page talking about this could help.

About adding an option to do it, I rather think that it might be more useful to add a new feature to make 'display_as' work with a helper method directly. People usually use this feature as a bridge to some other rails helper method, like number_to_currency or simple_format, so maybe provide a direct way to implement this could be a better solution.

About your note about the text beeing displayed without format during the ajax request you're right, we'll look into it and thanks for the catch!

rogercampos commented 12 years ago

Hi, I've just implemented a new feature display_with which provides direct bindings for view helpers. You can use it like this:

= best_in_place @user, :large_comment, :display_with => :simple_format
brianmaissy commented 12 years ago

When I do this: best_in_place user, :notes, :type => :textarea, :display_with => :simple_format I get this error: undefined method 'white_list_sanitizer' for Module:Class Am I using it wrong? I googled the error but the solutions didn't work. "Module:Class" is throwing me off. It's almost as if the helper is being called in the wrong context or on the wrong object?

tbuyle commented 12 years ago

Same error here.

edwallitt commented 12 years ago

and me too!

tbuyle commented 12 years ago

Added as a new issue : #78

albertbellonch commented 12 years ago

Hi all,

This issue is now solved with pull request #79.

You can checkout Rails Action View's SanitizeHelper, which includes sanitize(html, options = {}) (the method that ended up breaking), called from our old friend TextHelper's simple_format(text, html_options={}, options={}).

After some investigation, I realized that SanitizeHelper's white_list_sanitizer should always be initialized (check out this). But it wasn't! Was Ruby falling apart or something...?

The answer is no. The problem is that we used Action View's Helpers in the non-right way, without loading every single Helper as we should do. In our previous approach, the ClassMethods weren't correctly load, so our dear white_list_sanitizer wasn't initialized when accessed, and thus our call to simple_format was broken.

Now we are using an instance of ActionView::Base, so everything is loaded in a more right way, and everything keeps being as simple as always.

More insight can be found in here and here.

cmbankester commented 12 years ago

I still get this issue when doing, for example, best_in_place(model, :chart, type: :textarea, nil: 'Click to edit your chart', display_with: :simple_format). The error I get is this: undefined methodwhite_list_sanitizer' for Module:Class`. Also, I am using decorators a la Draper.

albertbellonch commented 12 years ago

Hello @cbanke1

Which best_in_place are you using? This fix is not yet in any version of the gem, so if you want to use it you have to use the gem directly from the git repository.

We are planning to do a release (which will be 1.0.5) in less than two weeks.

Did it fix the issue?

cmbankester commented 12 years ago

@albertbellonch No, I do not believe. I have it set in the gemfile as such: gem 'best_in_place', git: "https://github.com/bernat/best_in_place.git" but I still get the undefined method white_list_sanitizer exception.

Should I also specify a commit? It seems like pulling from github should pull the most recent master.

UPDATE: I think I fixed the issue, which was local. I'll come back if I have more information. Thanks for all your help!

diffractometer commented 11 years ago

Me 2

markmilman commented 11 years ago

same here

Akshg commented 8 years ago

I am using display_with: :simple_format. Its working fine. But then, the text does not remain editable at all. I tried fetching directly from git repo, but it doesn't help. Any input will be helpful. Thanks.

cg5544 commented 7 years ago

@Akshg I am running into the sample issue. :simple_format works but text is not editable anymore.

Akshg commented 7 years ago

@cg5544 Even i was am facing the same issue at that time. Any progress?