# HeLp oN my database

**URL:** <https://www.ruby-forum.com/t/help-on-my-database/178788>\
**Category:** Rails\
**Created:** [November 11, 2009, 11:54am UTC](https://www.ruby-forum.com/t/help-on-my-database/178788 "2009-11-11T11:54:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [November 11, 2009, 11:54am UTC](https://www.ruby-forum.com/t/help-on-my-database/178788/1 "2009-11-11T11:54:26Z")

</div>

Using my application i can able to save a new record into my db  
but i cannot update a existing record into my db.  
using update query i can able to update my records.  
but using update\_attributes it doesnot update my records.  
even i cant find any errors in logs or something.  
throughout my application i can able to save a new record but unable to  
update my existing records.  
actually i have changed my application to new db.since then i face these  
issues.  
before changing the db the application was working fine…  
so wat would be problem in my database or something…where i have to  
lookup  
Kindly Provide Me Your Views for my issue…

Thanks a bunch  
Have a Nice daY

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [November 11, 2009, 12:55pm UTC](https://www.ruby-forum.com/t/help-on-my-database/178788/2 "2009-11-11T12:55:18Z")

</div>

2009/11/11 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> before changing the db the application was working fine…  
> so wat would be problem in my database or something…where i have to  
> lookup  
> Kindly Provide Me Your Views for my issue…

Please post the code which attempts to update the record.  
If you are using update\_attributes what return value is it giving.  
Is it possible that you have validations that are failing?

Colin

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [November 12, 2009, 6:22am UTC](https://www.ruby-forum.com/t/help-on-my-database/178788/3 "2009-11-12T06:22:01Z")

</div>

Colin L. wrote:

> 2009/11/11 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > before changing the db the application was working fine…  
> > so wat would be problem in my database or something…where i have to  
> > lookup  
> > Kindly Provide Me Your Views for my issue…
> 
> Please post the code which attempts to update the record.  
> If you are using update\_attributes what return value is it giving.  
> Is it possible that you have validations that are failing?
> 
> Colin

Thank You for the Reply.

Kindly find my code below

if request.post? and params[:id] and params[:newsinfo]

@newsinfo = News.find(params[:id])

sql = "UPDATE news SET newstext = ‘today’ "

@check = ActiveRecord::Base.connection.execute(sql)

if @newsinfo.update\_attributes(params[:newsinfo])

```
flash[:notice] = "news has been successfully modified, click 'edit' 

```

to modify and ‘remove’ to delete flash news"

```
redirect_to :controller => 'news', :action => 'list'

```

else

```
   puts @newsinfo.errors.inspect

```

end

end

sql = "UPDATE news SET newstext = ‘today’ "

@check = ActiveRecord::Base.connection.execute(sql)

this code updates the db

but the below code not works still no errors

if @newsinfo.update\_attributes(params[:newsinfo])

```
flash[:notice] = "news has been successfully modified, click 'edit' 

```

to modify and ‘remove’ to delete flash news"

```
redirect_to :controller => 'news', :action => 'list'

```

else

```
   puts @newsinfo.errors.inspect

```

end

the control goes to if condition only.no validation errors

Any suggestion on this.

Thanks for information

Have a Pleasent daY

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [November 12, 2009, 6:33am UTC](https://www.ruby-forum.com/t/help-on-my-database/178788/4 "2009-11-12T06:33:12Z")

</div>

Newb N. wrote:

> Colin L. wrote:
> 
> > 2009/11/11 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> > 
> > > before changing the db the application was working fine…  
> > > so wat would be problem in my database or something…where i have to  
> > > lookup  
> > > Kindly Provide Me Your Views for my issue…

> > @newsinfo = News.find(1)  
> > =\> #\<News id: 1, newstext: “positive”\>  
> > @newsinfo.update\_attribute(:newstext,“attitude”)  
> > =\> true

i run the above script in my ruby console

it has outputed the above

Thanks for any ideas

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [November 12, 2009, 9:56am UTC](https://www.ruby-forum.com/t/help-on-my-database/178788/5 "2009-11-12T09:56:07Z")

</div>

2009/11/12 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Â else
> 
> Â Â Â puts @newsinfo.errors.inspect
> 
> Â end
> 
> the control goes to if condition only.no validation errors

Do you mean it goes to to the else condition but shows no errors? Or  
do you mean it passes the if test but the data is not updated in the  
db?

Colin

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [November 12, 2009, 11:06am UTC](https://www.ruby-forum.com/t/help-on-my-database/178788/6 "2009-11-12T11:06:22Z")

</div>

2009/11/12 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > the control goes to if condition only.no validation errors  
> > > Processing NewsController#modify (for 192.168.0.82 at 2009-11-12  
> > > Â [4;36;1mUserInfo Load (0.0ms) [0m Â Â [0;1mSELECT \* FROM `userinfo`  
> > > WHERE (`userinfo`.`id` IS NULL) LIMIT 1 [0m  
> > > Â [4;35;1mNews Columns (16.0ms) [0m Â Â [0mSHOW FIELDS FROM `news` [0m  
> > > Â [4;36;1mNews Load (0.0ms) [0m Â Â [0;1mSELECT \* FROM `news` WHERE  
> > > (`news`.`id` = 1) Â [0m  
> > > Â [4;35;1mSQL (0.0ms) [0m Â Â [0mBEGIN [0m  
> > > Â [4;36;1mSQL (0.0ms) [0m Â Â [0;1mCOMMIT [0m

There should be an UPDATE here, so for some reason rails is not  
changing the record. Are you absolutely sure that the field newstext  
has not already got the value revafgtfggfffrtyhrthfgjh? Have a look  
in phpmyadmin or whatever tool you use to look at the db and check.

Otherwise please post the complete code for NewsController#modify.

Colin

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [November 12, 2009, 10:14am UTC](https://www.ruby-forum.com/t/help-on-my-database/178788/7 "2009-11-12T10:14:10Z")

</div>

Colin L. wrote:

> 2009/11/12 Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Â else
> > 
> > Â Â Â puts @newsinfo.errors.inspect
> > 
> > Â end
> > 
> > the control goes to if condition only.no validation errors
> 
> Do you mean it goes to to the else condition but shows no errors? Or  
> do you mean it passes the if test but the data is not updated in the  
> db?
> 
> Colin

Thanks for the reply…  
it goes to the if statement only but not updating the records…

Processing NewsController#modify (for 192.168.0.82 at 2009-11-12  
14:25:40) [POST]  
Parameters: {“commit”=\>“Edit”, “id”=\>“1”,  
“newsinfo”=\>{“newstext”=\>“revafgtfggfffrtyhrthfgjh”}}  
e[4;36;1mSQL (0.0ms)e[0m e[0;1mSET SQL\_AUTO\_IS\_NULL=0e[0m  
::: Checking session expiry  
::: Session has not expired. Reinitialising.  
::: Initializing session expiry. Expires at Thu Nov 12 16:05:40 +0530  
2009  
e[4;35;1mUserInfo Columns (15.0ms)e[0m e[0mSHOW FIELDS FROM  
`userinfo`e[0m  
e[4;36;1mUserInfo Load (0.0ms)e[0m e[0;1mSELECT \* FROM `userinfo`  
WHERE (`userinfo`.`id` IS NULL) LIMIT 1e[0m  
e[4;35;1mNews Columns (16.0ms)e[0m e[0mSHOW FIELDS FROM `news`e[0m  
e[4;36;1mNews Load (0.0ms)e[0m e[0;1mSELECT \* FROM `news` WHERE  
(`news`.`id` = 1) e[0m  
e[4;35;1mSQL (0.0ms)e[0m e[0mBEGINe[0m  
e[4;36;1mSQL (0.0ms)e[0m e[0;1mCOMMITe[0m  
Redirected to actionlistcontrollernews  
Completed in 63ms (DB: 31) | 302 Found  
[[http://192.168.0.82/news/modify/1](http://192.168.0.82/news/modify/1)]

this is the log when i modify my news.

it has only one field .the field is newstext.

still its not getting updated.

Any Ideas
