I have a Model whose table name and primary key don''t follow Rails conventions. So I have used set_table_name() and set_primary_key() and can do the Record.find() method ok. My problem is that the Record.new(params[:id]) idiom in a controller complains: undefined method `stringify_keys!'' for "REAL_PKEY":String Is there something else I need to do?
On 7/6/05, Steve Downey <sldowney-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:> My problem is that the Record.new(params[:id]) idiom in a controller complains:This isn''t an answer as to exactly what your issue is but this may get you past this point if nothing else. I have been using the following with no issues rec = Record.new rec.id = params[:id] . . . rec.save Maybe there''s a bug in the direct initialization method that you are hitting which setting the id separately avoids????? Just a thought.... -- John W Higgins wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
On 7/6/05, John Higgins <wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7/6/05, Steve Downey <sldowney-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote: > > My problem is that the Record.new(params[:id]) idiom in a controller complains: > > This isn''t an answer as to exactly what your issue is but this may get > you past this point if nothing else. I have been using the following > with no issues > > rec = Record.new > rec.id = params[:id] > . > . > . > rec.save > > Maybe there''s a bug in the direct initialization method that you are > hitting which setting the id separately avoids????? > > Just a thought.... > > -- > John W Higgins > wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >ActiveRecord::Base#new expects a Hash of attributes and values that it will assign to the newly created object, not a string. Your params[:id] seems to simply be a string containing the value of the pkey you wish to insert. This is why you receive the error. Also, though AR does allow you to specify the column of the primary key, I''m not sure it likes you trying to set the value yourself. I''m pretty sure it still expects an autogenerated key. Hope that helps, Jason
On 7/6/05, Jason Foreman <threeve.org-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Also, though AR does allow you to specify the column of the primary > key, I''m not sure it likes you trying to set the value yourself. I''m > pretty sure it still expects an autogenerated key.AR is just fine with user defined keys (at least if your chosen db adapter doesn''t stomp on you) - you just have to remember to use idinstead of field_name= to set it. -- John W Higgins wishdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org