Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

line breaks in textareas #62

Closed
brianmaissy opened this issue Dec 20, 2011 · 15 comments
Closed

line breaks in textareas #62

brianmaissy opened this issue Dec 20, 2011 · 15 comments

Comments

@brianmaissy
Copy link

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link

tbuyle commented Jan 5, 2012

Same error here.

@edwallitt
Copy link

and me too!

@tbuyle
Copy link

tbuyle commented Jan 9, 2012

Added as a new issue : #78

@albertbellonch
Copy link
Collaborator

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
Copy link

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 method white_list_sanitizer' for Module:Class`.
Also, I am using decorators a la Draper.

@albertbellonch
Copy link
Collaborator

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
Copy link

@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
Copy link

Me 2

@markmilman
Copy link

same here

@Akshg
Copy link

Akshg commented Jan 1, 2016

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
Copy link

cg5544 commented Oct 27, 2016

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

@Akshg
Copy link

Akshg commented Feb 14, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants