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"} [4;36;1mSQL (0.010000) [0;1mPRAGMA table_info(collections) [4;35;1mSQL (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 -- Posted via http://www.ruby-forum.com/.
Steve Chanin
2006-Feb-22 22:10 UTC
[Rails] Save only inserts null instead of actual values
Nick, I''m not 100% sure, but take out the attr_accessor declaration in your model and see if that fixes things. I don''t have any of those in any of my models (which save correctly) and I recall having a problem once early on as a result of something similar. -Steve -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Nick Snels Sent: Wednesday, February 08, 2006 1:14 PM To: rails@lists.rubyonrails.org Subject: [Rails] Save only inserts null instead of actual values 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"} [4;36;1mSQL (0.010000) [0;1mPRAGMA table_info(collections) [4;35;1mSQL (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 -- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails