# Rails adding dashes to text field in db

**URL:** <https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247>\
**Category:** Rails\
**Created:** [April 17, 2007, 2:18pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247 "2007-04-17T14:18:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 17, 2007, 2:18pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247/1 "2007-04-17T14:18:30Z")

</div>

I have a model called notes. Here’s the definition in my schema.rb

create\_table “notes”, :force =\> true do |t|  
t.column “sales\_order\_id”, :integer  
t.column “content”, :text  
t.column “timestamp”, :datetime  
t.column “user\_id”, :integer  
end

The model class is as follows:

class Note \< ActiveRecord::Base  
belongs\_to :sales\_order  
belongs\_to :user  
end

I’m trying to add a note by doing the following in the  
sales\_order\_controller:

def add\_note  
da\_note = Note.new  
da\_note.sales\_order\_id = params[:so\_id]  
da\_note.content = params[:note\_body]  
da\_note.user\_id = cookies[:user\_id]  
da\_note.timestamp = Time.now

```
if da_note.save!
  flash[:notice] = 'Note added to Sales Order'
  redirect_to :action => 'show', :id => params[:so_id]
end

```

end

This works, but it adds the following text to the content field of every  
note: “-- -”. So if I type in ‘test note’ and submit, I get ‘— -  
test note’ in the db. What am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 17, 2007, 3:16pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247/2 "2007-04-17T15:16:22Z")

</div>

are you calling debug() in your view anywhere? or to\_yaml?

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 17, 2007, 4:12pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247/3 "2007-04-17T16:12:01Z")

</div>

Chris H. wrote:

> are you calling debug() in your view anywhere? or to\_yaml?

No, I tried that at first, but it didn’t help anything.

I just now changed

params[:note\_body]

to:

params[:note\_body].to\_s and it worked!

Why does it have to be changed to a string? Isn’t it already a string?

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 17, 2007, 4:19pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247/4 "2007-04-17T16:19:59Z")

</div>

Jason wrote:

> params[:note\_body].to\_s and it worked!
> 
> Why does it have to be changed to a string? Isn’t it already a string?

Only you can tell us. Still a breakpoint in there and have a look at the  
params hash.

Fred

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 17, 2007, 5:43pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247/5 "2007-04-17T17:43:10Z")

</div>

Frederick C. wrote:

> Jason wrote:
> 
> > params[:note\_body].to\_s and it worked!
> > 
> > Why does it have to be changed to a string? Isn’t it already a string?
> 
> Only you can tell us. Still a breakpoint in there and have a look at the  
> params hash.
> 
> Fred

I’m afraid you’ve gone over my head with that comment. What will the  
params hash tell me that I don’t already know?

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 17, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247/6 "2007-04-17T18:09:49Z")

</div>

Unfortunately no. Unlike Smalltalk and many other languages, in Ruby  
Symbols are not strings.

The value in params[:note\_body] was apparently a symbol not a string.

Michael

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 17, 2007, 5:54pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247/7 "2007-04-17T17:54:47Z")

</div>

you can just tail your development log and watch it as you post the  
data to the server. that should indicate where the problem is coming  
from. if you see – - in your params hash (posted data) then the  
problem is in your view. if it’s not, then the problem is in your  
controller method

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [April 17, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/rails-adding-dashes-to-text-field-in-db/92247/8 "2007-04-17T18:20:01Z")

</div>

> The value in params[:note\_body] was apparently a symbol not a string.

Ok, I guess it was a symbol, but I don’t have any idea how that  
happened. Oh well, it works now, at least.

Thanks everybody!
