Forum: Ruby on Rails rails adding junk into db

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
86fbe1d13676473496f4b39421466f7c?d=identicon&s=25 Scott Pn (darkomen1234)
on 2007-07-27 05:23
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?
B84d42a3a5c343f8fc6ab7d7f47fd3f5?d=identicon&s=25 Robby Russell (Guest)
on 2007-07-27 05:28
(Received via mailing list)
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 Russell
http://www.robbyonrails.com/
http://www.planetargon.com/
86fbe1d13676473496f4b39421466f7c?d=identicon&s=25 Scott Pn (darkomen1234)
on 2007-07-27 13:36
Robby Russell 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 Russell
> http://www.robbyonrails.com/
> http://www.planetargon.com/

well it puts in --- - when I do a submit to the db.
D7c511ce5025d37b8c6bd9134e0f2bd9?d=identicon&s=25 Thorsten (Guest)
on 2007-07-27 14:25
(Received via mailing list)
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 ;)
86fbe1d13676473496f4b39421466f7c?d=identicon&s=25 Scott Pn (darkomen1234)
on 2007-07-28 01:08
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 ;)

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):
<div class="comment">
  <% form_tag :controller => 'comment', :action => 'add_comment' do %>
    <label>Add a Comment:</comment><br />
    <%= text_area :comment, params[:comment], :value => '', :cols =>
"55", :rows => "6" %><br />
          <%= hidden_field :id, params[:id], :value => params[:id] %>
    <%= hidden_field :user_id, params[:user_id], :value =>
session[:user_id] %>
    <%= submit_tag "Add Comment" %>
  <% end %>
</div>

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
86fbe1d13676473496f4b39421466f7c?d=identicon&s=25 Scott Pn (darkomen1234)
on 2007-07-28 01:10
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).
Dfd6f9989147955682701da8227df8b4?d=identicon&s=25 Michael Wang (Guest)
on 2007-07-28 02:00
(Received via mailing list)
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 Wang
86fbe1d13676473496f4b39421466f7c?d=identicon&s=25 Scott Pn (darkomen1234)
on 2007-07-28 02:51
Michael Wang 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 Wang

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.
9f4e11fd04ca1e5a56d00ff3531104ed?d=identicon&s=25 Jean Nibee (jeannibee)
on 2007-07-28 05:38
Scott Pn wrote:
> Michael Wang 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 Wang
>
> 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.
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2007-07-28 07:24
(Received via mailing list)
Scott Pn wrote:

>     <%= text_area :comment, params[:comment], :value => '', :cols =>
> "55", :rows => "6" %><br />

This should instead be text_area_tag.

--
We develop, watch us RoR, in numbers too big to ignore.
86fbe1d13676473496f4b39421466f7c?d=identicon&s=25 Scott Pn (darkomen1234)
on 2007-07-28 16:42
Mark Reginald James wrote:
> Scott Pn wrote:
>
>>     <%= text_area :comment, params[:comment], :value => '', :cols =>
>> "55", :rows => "6" %><br />
>
> 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.
B09a3f6cdc4797532647d2d264b5df49?d=identicon&s=25 Jodi Showers (jshow)
on 2007-07-28 16:50
(Received via mailing list)
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
86fbe1d13676473496f4b39421466f7c?d=identicon&s=25 Scott Pn (darkomen1234)
on 2007-07-30 02:48
Jodi Showers 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?
835294a2661ef37b591e5618e5a7b4b2?d=identicon&s=25 Tore Darell (Guest)
on 2007-07-30 11:02
(Received via mailing list)
On Fri, 2007-07-27 at 13:36 +0200, Scott Pn wrote:
> Robby Russell 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 Darell <toredarell@gmail.com>
F4638db31a256d9247ecc799f7522c4d?d=identicon&s=25 Scott Eckenrode (seckenrode)
on 2007-07-30 13:26
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):
> <div class="comment">
>   <% form_tag :controller => 'comment', :action => 'add_comment' do %>
>     <label>Add a Comment:</comment><br />
>     <%= text_area :comment, params[:comment], :value => '', :cols =>
> "55", :rows => "6" %><br />
>           <%= hidden_field :id, params[:id], :value => params[:id] %>
>     <%= hidden_field :user_id, params[:user_id], :value =>
> session[:user_id] %>
>     <%= submit_tag "Add Comment" %>
>   <% end %>
> </div>
>

check 3rd line of div ... is that an errant close </comment> instead of
</label> tag typo here or in actual code ?
86fbe1d13676473496f4b39421466f7c?d=identicon&s=25 Scott Pn (darkomen1234)
on 2007-07-31 00:51
Scott Eckenrode wrote:
>
> check 3rd line of div ... is that an errant close </comment> instead of
> </label> 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 Darell or anyone really: What do you mean by AR?
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2007-07-31 03:07
(Received via mailing list)
Hi Scott,

Scott Pn wrote:

> And to Tore Darell or anyone really:

Speaking for 'anyone' ...;-)

> What do you mean by AR?

ActiveRecord

Best regards,
Bill
This topic is locked and can not be replied to.