Rails adding junk into db

I am having a problem where I am getting data from a form and when it
get puts into the database there is extra unwanted junk there, and I
don’t know why it is doing it. Has anyone had any problems like this?

Robby R. wrote:

Anything that is saved in the database would be going through any
validations and filters that you put in place.

Perhaps you could elaborate on what “junk” is.

Robby


Robby R.
http://www.robbyonrails.com/
http://www.planetargon.com/

well it puts in — - when I do a submit to the db.

Scott Pn wrote:

I am having a problem where I am getting data from a form and when it
get puts into the database there is extra unwanted junk there, and I
don’t know why it is doing it. Has anyone had any problems like this?

Anything that is saved in the database would be going through any
validations and filters that you put in place.

Perhaps you could elaborate on what “junk” is.

Robby


Robby R.
http://www.robbyonrails.com/

it puts in — - ?
you mean dashes? and where does it put that in? what column? what
column type? what does your model and controller code look like?

We’re no mindreaders mister :wink:

Thorsten wrote:

it puts in — - ?
you mean dashes? and where does it put that in? what column? what
column type? what does your model and controller code look like?

We’re no mindreaders mister :wink:

Sorry, should have just posted some code in the first place.

Here is the partial I am using to submit the comment.
(/partial/_add_comment.rhtml):

<% form_tag :controller => 'comment', :action => 'add_comment' do %> Add a Comment:
<%= text_area :comment, params[:comment], :value => '', :cols => "55", :rows => "6" %>
<%= hidden_field :id, params[:id], :value => params[:id] %> <%= hidden_field :user_id, params[:user_id], :value => session[:user_id] %> <%= submit_tag "Add Comment" %> <% end %>

Here is the controller code that creates the comment object and puts it
into the DB:
def add_comment
@comment = Comment.new
@comment.comment = params[:comment]
@comment.user_id = params[:user_id]
@comment.date = Time.now
if @comment.save
flash[:notice] = “Comment added successfully”
redirect_to(:controller => :profile, :action => :show, :id =>
params[:id])
else
flash[:notice] = “Comment didn’t submit properly, please try again
later”
end
end

And the model looks like this:
class Comment < ActiveRecord::Base
belongs_to :users

validates_presence_of :comment
end

Oh yeah I should mention it puts “|---- - comment here” into the db
table (to be a little more precise on what I meant by junk).

Michael W. wrote:

That string is coming from somewhere. I’m guessing it’s a mistyped HTML
comment in one of your view files. Look at the HTML source of the page
after its been rendered by Rails to see where that string is on the page
and work back from there or just rgrep the directory to find it.


Michael W.

I don’t know where it is coming from but here is what’s being put into
the db table from the log file:
INSERT INTO comments (date, profile_id, user_id, comment)
VALUES(‘2007-07-27 20:48:55’, 1, 1, ‘— \n- |\n test 66\r\n\n’)

So weird that stuff is literally coming out of no where.

Scott Pn wrote:

Oh yeah I should mention it puts “|---- - comment here” into the db
table (to be a little more precise on what I meant by junk).

That string is coming from somewhere. I’m guessing it’s a mistyped HTML
comment in one of your view files. Look at the HTML source of the page
after its been rendered by Rails to see where that string is on the page
and work back from there or just rgrep the directory to find it.


Michael W.

Scott Pn wrote:

<%= text_area :comment, params[:comment], :value => '', :cols => 

“55”, :rows => “6” %>

This should instead be text_area_tag.


We develop, watch us RoR, in numbers too big to ignore.

Mark Reginald J. wrote:

Scott Pn wrote:

<%= text_area :comment, params[:comment], :value => '', :cols => 

“55”, :rows => “6” %>

This should instead be text_area_tag.


We develop, watch us RoR, in numbers too big to ignore.

The text_area_tag had no effect on that input. This is really
mindboggling.

On 28-Jul-07, at 10:42 AM, Scott Pn wrote:

We develop, watch us RoR, in numbers too big to ignore.

The text_area_tag had no effect on that input. This is really
mindboggling.

Scoff, this is a key time to decouple.

write some model(unit) tests. The tests ‘should’ verify the results
of a save.

then write a controller(functional) spec. Will do the same, but test
your controller layer.

these 2 tests will be guaranteed to give you the symptoms you need to
lick this bug (eww) dead.

cheers,
Jodi

Scott Pn wrote:

Michael W. wrote:

That string is coming from somewhere. I’m guessing it’s a mistyped HTML
comment in one of your view files. Look at the HTML source of the page
after its been rendered by Rails to see where that string is on the page
and work back from there or just rgrep the directory to find it.


Michael W.

I don’t know where it is coming from but here is what’s being put into
the db table from the log file:
INSERT INTO comments (date, profile_id, user_id, comment)
VALUES(‘2007-07-27 20:48:55’, 1, 1, ‘— \n- |\n test 66\r\n\n’)

So weird that stuff is literally coming out of no where.

I would suggest outputting the values of the info being sent into your
controller / model. Also, check your form and do a ‘view source’ just to
make sure that it’s not ‘special HTML’ formating.

I.E. If you are hitting enter in the comments field to make a multi line
comment, then that \r\n stuff wouldn’t be garbage, it would formatting
code for the box.

On Fri, 2007-07-27 at 13:36 +0200, Scott Pn wrote:

Robby R. wrote:

Anything that is saved in the database would be going through any
validations and filters that you put in place.

Perhaps you could elaborate on what “junk” is.

well it puts in — - when I do a submit to the db.

That looks like the start of a YAML document. Is the column serialised?
Maybe AR is doing something funky because the column name is the same as
the model name?


Tore D. [email protected]

Jodi S. wrote:

On 28-Jul-07, at 10:42 AM, Scott Pn wrote:

We develop, watch us RoR, in numbers too big to ignore.

The text_area_tag had no effect on that input. This is really
mindboggling.

Scoff, this is a key time to decouple.

write some model(unit) tests. The tests ‘should’ verify the results
of a save.

then write a controller(functional) spec. Will do the same, but test
your controller layer.

these 2 tests will be guaranteed to give you the symptoms you need to
lick this bug (eww) dead.

cheers,
Jodi

How do I write tests for this. I looked around at the test stuff in the
test folder, but I don’t what I am supposed to change to check the model
and controller?

Scott Pn wrote:

Sorry, should have just posted some code in the first place.

Here is the partial I am using to submit the comment.
(/partial/_add_comment.rhtml):

<% form_tag :controller => 'comment', :action => 'add_comment' do %> Add a Comment:
<%= text_area :comment, params[:comment], :value => '', :cols => "55", :rows => "6" %>
<%= hidden_field :id, params[:id], :value => params[:id] %> <%= hidden_field :user_id, params[:user_id], :value => session[:user_id] %> <%= submit_tag "Add Comment" %> <% end %>

check 3rd line of div … is that an errant close instead of
tag typo here or in actual code ?

Hi Scott,

Scott Pn wrote:

And to Tore D. or anyone really:

Speaking for ‘anyone’ …:wink:

What do you mean by AR?

ActiveRecord

Best regards,
Bill

Scott Eckenrode wrote:

check 3rd line of div … is that an errant close instead of
tag typo here or in actual code ?
Yeah that was an error, but it wasn’t effecting the code that I had for
the comment.

And to Tore D. or anyone really: What do you mean by AR?