Db change not reflected in app

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!

On 16 March 2010 14:35, Jeff R. [email protected] 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
:slight_smile:

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.

Michael P. wrote:

On 16 March 2010 14:35, Jeff R. [email protected] 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
:slight_smile:

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?

Michael P. wrote:

On 16 March 2010 14:55, Jeff R. [email protected] 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.

On 16 March 2010 14:55, Jeff R. [email protected] 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)

Hassan S. wrote:

On Tue, Mar 16, 2010 at 7:55 AM, Jeff R. [email protected]
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. ------------------------ [email protected]
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?

On Tue, Mar 16, 2010 at 7:55 AM, Jeff R. [email protected]
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. ------------------------ [email protected]
twitter: @hassan

On Tue, Mar 16, 2010 at 8:19 AM, Jeff R. [email protected]
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://railscasts.com/
http://peepcode.com/

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

HTH,

Hassan S. ------------------------ [email protected]
twitter: @hassan