# Database updates doesn't update input fields

**URL:** <https://www.ruby-forum.com/t/database-updates-doesnt-update-input-fields/92935>\
**Category:** Rails\
**Created:** [April 25, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/database-updates-doesnt-update-input-fields/92935 "2007-04-25T20:35:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 8:35pm UTC](https://www.ruby-forum.com/t/database-updates-doesnt-update-input-fields/92935/1 "2007-04-25T20:35:43Z")

</div>

Hi there,

I’m a compete Rails n00b and trying to understand how this thing works  
so any help is greatly appreciated.

I created a table using migrations, so far so good. My view shows the  
list and I can add new records. Now I forgot one column so I added it by  
creation a new migration file with an add\_column. Raked this migration  
and checked the database, it’s there.

When I go to my listing web-page the listing is updated BUT, when I  
click the New link on this page the input forms still show the old  
structure and my newly added column doesn’t show up.

I tried to do this without migrations (manually in the database),  
restarted Apache, restarted MySQL, migrated to version 0 and back and it  
still doesn’t show up.

What am I missing here?

Many thanks!

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/database-updates-doesnt-update-input-fields/92935/2 "2007-04-25T20:39:36Z")

</div>

Guest wrote:

> Hi there,
> 
> I’m a compete Rails n00b and trying to understand how this thing works  
> so any help is greatly appreciated.
> 
> I created a table using migrations, so far so good. My view shows the  
> list and I can add new records. Now I forgot one column so I added it by  
> creation a new migration file with an add\_column. Raked this migration  
> and checked the database, it’s there.
> 
> When I go to my listing web-page the listing is updated BUT, when I  
> click the New link on this page the input forms still show the old  
> structure and my newly added column doesn’t show up.

Could show your view code, and your controller code?

Stephan

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 9:12pm UTC](https://www.ruby-forum.com/t/database-updates-doesnt-update-input-fields/92935/3 "2007-04-25T21:12:06Z")

</div>

## Guest wrote:

> # New blogpost
> 
> \<% form\_tag :action =\> ‘create’ do %\>  
> \<%= render :partial =\> ‘form’ %\>  
> \<%= submit\_tag “Create” %\>  
> \<% end %\>
> 
> ## \<%= link\_to ‘Back’, :action =\> ‘list’ %\>
> 
> Many thanks!

Well those scaffold just get you started. They are not really designed  
to continually reflect on your database structure. After you generate  
them you are expected to maintain them yourself. This is not a  
limitation, it’s designed to make you move past that featureless ugly  
scaffold and into wherever you want to go.

So to add that new field to your forms, you need to add the view code  
for it. As you can see in your new.rhtml file, it render the partial  
called “form”. Look in that same folder for a file named “\_form.rhtml”  
because that is what is being rendered.

Copy one of the existing form field declarations and change the field  
name its accessing.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 9:18pm UTC](https://www.ruby-forum.com/t/database-updates-doesnt-update-input-fields/92935/4 "2007-04-25T21:18:54Z")

</div>

Yes!

Thanks, have been looking for this for days and never got to the  
\_form.rhtml. Doh! I can see it new, off course you don’t need the  
duplicate code in the edit.rhtml and new.rhtml so this makes sense.

Thanks Alex, this hold me back from going on, thanks to you I found the  
motivation again.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/database-updates-doesnt-update-input-fields/92935/5 "2007-04-25T20:52:19Z")

</div>

Sure I can.

This is the blog\_admin\_controller which I didn’t change:

* * *

class BlogAdminController \< ApplicationController  
def index  
list  
render :action =\> ‘list’  
end

# GETs should be safe (see

[URIs, Addressability, and the use of HTTP GET and POST](http://www.w3.org/2001/tag/doc/whenToUseGet.html))  
verify :method =\> :post, :only =\> [:destroy, :create, :update],  
:redirect\_to =\> { :action =\> :list }

def list  
@blogpost\_pages, @blogposts = paginate :blogposts, :per\_page =\> 10  
end

def show  
@blogpost = Blogpost.find(params[:id])  
end

def new  
@blogpost = Blogpost.new  
end

def create  
@blogpost = Blogpost.new(params[:blogpost])  
if @blogpost.save  
flash[:notice] = ‘Blogpost was successfully created.’  
redirect\_to :action =\> ‘list’  
else  
render :action =\> ‘new’  
end  
end

def edit  
@blogpost = Blogpost.find(params[:id])  
end

def update  
@blogpost = Blogpost.find(params[:id])  
if @blogpost.update\_attributes(params[:blogpost])  
flash[:notice] = ‘Blogpost was successfully updated.’  
redirect\_to :action =\> ‘show’, :id =\> @blogpost  
else  
render :action =\> ‘edit’  
end  
end

## def destroy Blogpost.find(params[:id]).destroy redirect\_to :action =\> ‘list’ end end

And my view code, I suppose you mean the new.rhtml as this is the page  
that isn’t updated. The edit function also shows the outdated table  
structure.

* * *

# New blogpost

\<% form\_tag :action =\> ‘create’ do %\>  
\<%= render :partial =\> ‘form’ %\>  
\<%= submit\_tag “Create” %\>  
\<% end %\>

## \<%= link\_to ‘Back’, :action =\> ‘list’ %\>

Many thanks!
