# Saving rich text to the database

**URL:** <https://www.ruby-forum.com/t/saving-rich-text-to-the-database/161327>\
**Category:** Rails\
**Created:** [February 25, 2009, 3:09pm UTC](https://www.ruby-forum.com/t/saving-rich-text-to-the-database/161327 "2009-02-25T15:09:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 25, 2009, 3:09pm UTC](https://www.ruby-forum.com/t/saving-rich-text-to-the-database/161327/1 "2009-02-25T15:09:30Z")

</div>

I’ve started trying to use the wysihat rich text editor from 37-  
signals and everything is going well except that I get an error when  
trying to save the text from the enhanced field to the database. This  
is from my log:

Processing InstructionsController#new (for 127.0.0.1 at 2009-02-25  
06:04:57) [POST]  
Session ID:  
BAh7CCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo  
%0ASGFzaHsABjoKQHVzZWR7ADoMY3NyZl9pZCIlMjNkODY3MzA1YTVkMmQ2MTgw  
%0AZDdhZTA1Y2I1OTZlZmI6CXVzZXJpCQ%3D%3D–  
f732f8aee1da43652706372f3d32f66ce203b19b  
Parameters: {“commit”=\>“Create”, “instruction”=\>  
{“description”=\>“first\nsecond\nthird”},  
“authenticity\_token”=\>“88c467dd4b6f308ac40ebd2025a5193874f5ac0f”,  
“action”=\>“new”, “controller”=\>“instructions”}  
[4;36;1mUser Columns (0.004000) [0m [0;1mSHOW FIELDS FROM  
`users` [0m  
[4;35;1mUser Load (0.000000) [0m [0mSELECT \* FROM `users` WHERE  
(`users`.`id` = 4) [0m  
[4;36;1mInstruction Columns (0.003000) [0m [0;1mSHOW FIELDS FROM  
`instructions` [0m  
[4;35;1mSQL (0.000000) [0m [0mBEGIN [0m  
[4;36;1mInstruction Create (0.000000) [0m [0;1mINSERT INTO  
`instructions` (`start_day`, `title`, `description`, `appointment_id`,  
`frequency`) VALUES(NULL, NULL, ‘first\nsecond\nthird’, NULL, NULL)  
[0m  
[4;35;1mSQL (0.063000) [0m [0mCOMMIT [0m

NoMethodError (You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.call):

How do I go about saving text from this field to the database? Does  
it save it as html markup?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 26, 2009, 2:17am UTC](https://www.ruby-forum.com/t/saving-rich-text-to-the-database/161327/2 "2009-02-26T02:17:43Z")

</div>

Couple of questions: first, what happens if you copy and paste the  
insert SQL into your database and run it (i.e., are you sure the SQL  
works on your db)? Second, what is in your log after the NoMethodError  
message?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 26, 2009, 4:30am UTC](https://www.ruby-forum.com/t/saving-rich-text-to-the-database/161327/3 "2009-02-26T04:30:46Z")

</div>

I’ve been trying to figure this out and I don’t think its an issue  
with the database. When the form is submitted, its contents are blank  
everytime, so it is not submitting correctly. I have made a pastie  
with my console output, ignore the template error, I am just trying to  
get it to submit the contents of the text area:  
[http://pastie.org/400591](http://pastie.org/400591).

Has anyone been able to use the wysihat library and successfully save  
to the database?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 26, 2009, 6:24am UTC](https://www.ruby-forum.com/t/saving-rich-text-to-the-database/161327/4 "2009-02-26T06:24:17Z")

</div>

Okay I figured it out. I emailed Josh, the author of the library and  
this was his response:

If you using the 0.1 release it should automatically sync the  
description textarea and the rich text area.

In on the latest version, I disabled this feature by default because  
it was slowing alot of browsers down. So you can manually flush the  
content out with “editor.save();”. So you could do  
onclick=“editor.save();” or something like that.

So I also had to make editor a global variable and then I included  
editor.save() in :before with  
submit\_to\_remote
