0

I have Book.description with the following stored in the database:

    aaa

    bbb

    test

    fsdfdsfs fds fd sf sdf ds

I need to display the above including the line breaks in my view page.

I tried <%= @book.description.gsub(/\n/, '<br />')%> but I am getting the following error message :

private method `gsub' called for #<Hash:0xb662aa50>

I also tried <%= @book.description.html_safe%> but am getting the error message below:

undefined method `html_safe' for #<Hash:0xb66625f4>

Any suggestion ragarding this issue is most appreciated.

2
  • Could you include the @book.description.to_s to the question, to inspect its real content? Commented Aug 8, 2012 at 13:32
  • It's a Hash, not a string, to methods like gsub and html_safe obviously will not work on it. If the hash values are the strings you showed, you'll have to collect them first and then joining them with a BR tag will work. Commented Aug 8, 2012 at 13:35

1 Answer 1

1
<%= simple_format(@book.description) %>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the suggestion but using simple_format displays everything on one line. I want to display the database contents like it is stored in the table column including the line breaks
Simple format does that. There must be something else going on.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.