# Db change not reflected in app

**URL:** <https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236>\
**Category:** Rails\
**Created:** [March 16, 2010, 3:35pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236 "2010-03-16T15:35:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wirelesspower](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/58956e/32.png) [@wirelesspower](https://www.ruby-forum.com/u/wirelesspower)\
**Post date:** [March 16, 2010, 3:35pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236/1 "2010-03-16T15:35:53Z")

</div>

Hi folks.

I’m just starting to learn ruby and rails, and I’m working through a  
tutorial.

I’ve hit a hurdle attempting to add a column to a table. I’ve created  
the migration file and ran it through rake, and I can see that the db  
(mysql) has changed.

However, from what I’ve read, this new column should immediately be  
reflected in the app; in other words, when I create a new widget in the  
app, a new form field should appear on the page. But, this isn’t  
happening.

Can anybody explain why? Thanks!

---

<div class="post-metadata">

**Author:** ![wirelesspower](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/58956e/32.png) [@wirelesspower](https://www.ruby-forum.com/u/wirelesspower)\
**Post date:** [March 16, 2010, 3:50pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236/2 "2010-03-16T15:50:40Z")

</div>

On 16 March 2010 14:35, Jeff R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> However, from what I’ve read, this new column should immediately be  
> reflected in the app; in other words, when I create a new widget in the  
> app, a new form field should appear on the page. But, this isn’t  
> happening.

Being “reflected in the app” and appearing on the page are two different  
things.

The field _is_ available as a method on the model, but it’s not going  
to appear on any page (other than a list that is iterating through all  
the model’s columns) unless you put it there. It would be highly  
annoying if every time you added a field it appeared randomly on views  
🙂

You need to edit the view file (the erb, or rhtml if it’s an older  
version of Rails) and put the HTML to display the field you’ve created  
wherever you want it to appear.

if you want to be _sure_, you can add \<%= @model.my\_new\_field %\>  
anywhere in the view, and edit a record in the DB - refresh to see  
your DB-edited value.

---

<div class="post-metadata">

**Author:** ![wirelesspower](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/58956e/32.png) [@wirelesspower](https://www.ruby-forum.com/u/wirelesspower)\
**Post date:** [March 16, 2010, 3:55pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236/3 "2010-03-16T15:55:37Z")

</div>

Michael P. wrote:

> On 16 March 2010 14:35, Jeff R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > However, from what I’ve read, this new column should immediately be  
> > reflected in the app; in other words, when I create a new widget in the  
> > app, a new form field should appear on the page. But, this isn’t  
> > happening.
> 
> Being “reflected in the app” and appearing on the page are two different  
> things.
> 
> The field _is_ available as a method on the model, but it’s not going  
> to appear on any page (other than a list that is iterating through all  
> the model’s columns) unless you put it there. It would be highly  
> annoying if every time you added a field it appeared randomly on views  
> 🙂
> 
> You need to edit the view file (the erb, or rhtml if it’s an older  
> version of Rails) and put the HTML to display the field you’ve created  
> wherever you want it to appear.
> 
> if you want to be _sure_, you can add \<%= @model.my\_new\_field %\>  
> anywhere in the view, and edit a record in the DB - refresh to see  
> your DB-edited value.

Thanks.

According to “Agile Web D. with Rails”, the field should  
automagically appear on views, but that was using rails 1.2 and using  
scaffold in the controller. I’m running rails 2.3.x, so wasn’t able to  
use “scaffold” in the way described in the book.

Does that explain the (mis)behavior?

---

<div class="post-metadata">

**Author:** ![wirelesspower](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/58956e/32.png) [@wirelesspower](https://www.ruby-forum.com/u/wirelesspower)\
**Post date:** [March 16, 2010, 4:16pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236/4 "2010-03-16T16:16:36Z")

</div>

Michael P. wrote:

> On 16 March 2010 14:55, Jeff R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > According to “Agile Web D. with Rails”, the field should  
> > automagically appear on views, but that was using rails 1.2 and using  
> > scaffold in the controller. I’m running rails 2.3.x, so wasn’t able to  
> > use “scaffold” in the way described in the book.
> > 
> > Does that explain the (mis)behavior?
> 
> Which version of the book have you got?! If it’s v2 or earlier, lots  
> of it is going to be wrong for the version you have installed, which  
> is going to be very frustrating at times.

2nd edition, 2006.

> But yes - the scaffolding used to loop through all the columns :
> 
> \<% for column in License.content\_columns %\>
> 
> **\<%= column.human\_name %\>:** \<%=h @license.send(column.name) %\>
> 
> \<% end %\>
> 
> …but that’s intensely annoying because you have to _totally_ remove  
> it to replace it with anything useful.
> 
> Now, the individual fields get rendered one after an other - so you  
> can tweak the scaffolded file, rather than re-write it completely.
> 
> (of course the down side is if you add a new field to the db, you have  
> to add it to the view)

Thank you.

---

<div class="post-metadata">

**Author:** ![wirelesspower](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/58956e/32.png) [@wirelesspower](https://www.ruby-forum.com/u/wirelesspower)\
**Post date:** [March 16, 2010, 4:07pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236/5 "2010-03-16T16:07:38Z")

</div>

On 16 March 2010 14:55, Jeff R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> According to “Agile Web D. with Rails”, the field should  
> automagically appear on views, but that was using rails 1.2 and using  
> scaffold in the controller. I’m running rails 2.3.x, so wasn’t able to  
> use “scaffold” in the way described in the book.
> 
> Does that explain the (mis)behavior?

Which version of the book have you got?! If it’s v2 or earlier, lots  
of it is going to be wrong for the version you have installed, which  
is going to be very frustrating at times.

But yes - the scaffolding used to loop through all the columns :

\<% for column in License.content\_columns %\>

**\<%= column.human\_name %\>:** \<%=h @license.send(column.name) %\>

\<% end %\>

…but that’s intensely annoying because you have to _totally_ remove  
it to replace it with anything useful.

Now, the individual fields get rendered one after an other - so you  
can tweak the scaffolded file, rather than re-write it completely.

(of course the down side is if you add a new field to the db, you have  
to add it to the view)

---

<div class="post-metadata">

**Author:** ![wirelesspower](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/58956e/32.png) [@wirelesspower](https://www.ruby-forum.com/u/wirelesspower)\
**Post date:** [March 16, 2010, 4:19pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236/6 "2010-03-16T16:19:33Z")

</div>

Hassan S. wrote:

> On Tue, Mar 16, 2010 at 7:55 AM, Jeff R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > According to “Agile Web D. with Rails”, the field should  
> > automagically appear on views, but that was using rails 1.2 and using  
> > scaffold in the controller. I’m running rails 2.3.x, so wasn’t able to  
> > use “scaffold” in the way described in the book.
> 
> You’re setting yourself up for continuous pain and frustration by using  
> an out-of-date reference with a current Rails version.
> 
> Toss that book and get the latest, or use online tutorials based on the  
> 2.3.x branch. Really.
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid  
> twitter: @hassan

Ok - thanks for the warning.

Are there online tutorials you would recommend, for an experienced Java  
programmer who is new to ruby and rails?

---

<div class="post-metadata">

**Author:** ![wirelesspower](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/58956e/32.png) [@wirelesspower](https://www.ruby-forum.com/u/wirelesspower)\
**Post date:** [March 16, 2010, 4:17pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236/7 "2010-03-16T16:17:35Z")

</div>

On Tue, Mar 16, 2010 at 7:55 AM, Jeff R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> According to “Agile Web D. with Rails”, the field should  
> automagically appear on views, but that was using rails 1.2 and using  
> scaffold in the controller. I’m running rails 2.3.x, so wasn’t able to  
> use “scaffold” in the way described in the book.

You’re setting yourself up for continuous pain and frustration by using  
an out-of-date reference with a current Rails version.

Toss that book and get the latest, or use online tutorials based on the  
2.3.x branch. Really.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![wirelesspower](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/58956e/32.png) [@wirelesspower](https://www.ruby-forum.com/u/wirelesspower)\
**Post date:** [March 16, 2010, 4:41pm UTC](https://www.ruby-forum.com/t/db-change-not-reflected-in-app/185236/8 "2010-03-16T16:41:00Z")

</div>

On Tue, Mar 16, 2010 at 8:19 AM, Jeff R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Are there online tutorials you would recommend, for an experienced Java  
> programmer who is new to ruby and rails?

Coming from a similar background, I’ve gotten a lot out of:

[http://guides.rubyonrails.org/](http://guides.rubyonrails.org/)  
[http://railscasts.com/](http://railscasts.com/)  
[http://peepcode.com/](http://peepcode.com/)

and of course hanging out here and on the #ror irc channel 🙂

## HTH,

Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan
