Database updates doesn't update input fields

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!

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

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.

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.

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)
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!