Forum: Ruby on Rails Save only inserts null instead of actual values

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
91308e9bc88cb069fd1bcf88e910d042?d=identicon&s=25 Nick Snels (nicksnels)
on 2006-02-08 22:14
Hi,

whenever I try to save my form, rails only enters null values in my
database. I'm using sqlite, I thought that sqlite might be the problem,
but the problem remains when I switched to mysql. Here is my code:

controller:
class CollectionController < ApplicationController
  def new
    @collection = Collection.new
  end

  def create
    if request.get?
      redirect_to :action => 'new'
    elsif request.post?
      @collection = Collection.new(params[:collection])
      if @collection.save
        flash[:notice] = 'Collection was successfully created.'
        redirect_to :action => 'list'
      else
        render :action => 'new'
      end
    end
  end
end

model:
class Collection < ActiveRecord::Base
  has_many :subcollections

  attr_accessor :name, :description, :index_date
end

database.yml:
development:
  adapter: sqlite3
  dbfile: db/dev.db

development.log - after submitting data with the form
Processing CollectionController#create (for 127.0.0.1 at 2006-02-08
22:13:53) [POST]
  Parameters: {"commit"=>"Opslaan", "collection"=>{"name"=>"dqsfqds",
"description"=>"qfdsqsd"}, "action"=>"create",
"controller"=>"collection"}
  SQL (0.010000)   PRAGMA table_info(collections)
  SQL (0.000000)   INSERT INTO collections ("name",
"description", "index_date") VALUES(NULL, NULL, NULL)
Redirected to http://localhost:3000/collection/list
Completed in 0.17000 (5 reqs/sec) | DB: 0.01000 (5%) | 302 Found
[http://localhost/collection/create]


I really don't see it, I really don't. It is probably something very
stupid! All help is greatly appreciated.

Kind regards,

Nick
This topic is locked and can not be replied to.