Topic: Why is my script not writing to the database?

I don't understand this.  I've gotten things to work before but this particular thing refuses too.  No mistypes as far as I can tell.  Please help.

The Model - category.rb

class Category < ActiveRecord::Base
  def name
    "#{category_name}"
  end
end

The Controller - category_controller.rb
  def new
    @category = Category.new
    @page_title = "New Category"
  end

The _form
<%= error_messages_for 'category' %>

<p><label for="category_name">Category Name</label><br/>
<%= text_field 'category', 'category_name' %></p>


The database is MySQL the table is 'categories' and the only fields are 'id' and 'category_name'

Other parts connect to other table in the database so I can't figure out why this one doesn't.

Re: Why is my script not writing to the database?

You must create valid Object and the save it:

def new
    @category = Category.new(params[:category])
    @category.save
    @page_title = "New Category"
  end

Re: Why is my script not writing to the database?

okay, I'm not sure as I'm learning but two things that I've been doing are

@category = Category.new(params[:category])

and

@category.save

hope that helps

--

Re: Why is my script not writing to the database?

DOH!  Forgot to show you that part.  So what else do you think it could be?

  def create
    @category = Category.new(params[:category])
    if @category.save
      flash[:notice] = "Category #{@category.name} was successfully created."
      redirect_to :action => 'index'
    else
      @page_title = "Create New Category"
      render :action => 'new'
    end
  end

and the category will show up on the page and I can delete it but will not show up in the database at all.  I also can't edit it.  So i'm really confused.  thanks again.

Last edited by erikb (2006-11-26 13:46:51)

Re: Why is my script not writing to the database?

nevermind.....i'm an idiot as usual.(my typing sux)

Last edited by erikb (2006-11-26 17:33:33)