On Sun, 2006-04-02 at 11:47 -0700, Tom M. wrote:
snip…
@question = Question.new
some reason params[:parent_quiz] is a HashWithIndifferentAccess (not a
string) that needs to be dereferenced before it is passed down into
the
lower layers.
Two things:
- If you’re getting a HashWithIndifferentAccess, then something is
wrong.
I agree. But what?
params[:parent_quiz] is (allegedly) coming directly from the browser
parameters at this point. The only thing that processes it before I get
to it is the Rails framework. If there is a bug in that part of the
framework then I need to understand a bit more before I expend effort
trying to patch it.
Perhaps (just guessing) you need something like:
params[:parent_quiz][:id]
Tried it. Got the Rails equivalent of “Watchu talking 'bout
Willis?” (see stdout log)
Couldn’t find Quiz without an ID
RAILS_ROOT: script/…/config/…
Application Trace | Framework Trace | Full Trace
/usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:409:in
find' ./script/../config/../app/controllers/question_controller.rb:39:in
create’
- Id’s should be integers, not strings.
The assumption behind this is that all databases are centralized. There
are many applications where databases must be decentralized and merged
on demand. Integers do not guarantee uniqueness once you have split the
database across multiple pieces of hardware that cannot communicate with
each other. Assigning integer ranges to hardware systems is a sure
recipe for long-term problems (been there done that).
An example of this is the first database application I wrote for a
construction company. One of the infrastructure constraints was that
most sites went in before there was communications. The cell tower was
usually erected about 2 weeks after crews demobilized. But we had to be
able to merge the field and office data on demand at least once per week
during construction.
The use of UUID’s as primary keys is accepted practice for this sort of
application. Since most DBMS’ do not support UUID’s natively yet,
representing them as strings is a normal practice. UUID’s are
guaranteed unique in the world until the year 3040 or so because they
combine physical characteristics of the generating machine, time stamp,
and a random factor to generate the resulting value.
Also, see my patch to ActiveRecord.Acts.List. Primary keys that
are not
integers are not properly quoted on the reselect that follows the
insert.
Rails doesn’t support primary keys that aren’t integers.
According to “Agile” book, Rails does support this. According to
reality, it appears to be just a very thin sliver shy of full support.
It’s likely more than acts_as_list will need to be patched to “fix”
this.
I suspect that the other acts_as… methods would also require the same
patch.
I had to adapt a bit, but review of the Rails code showed me that if the
class provides an ID on creation, Rails will not override it. I have a
UUID helper mixin that I lifted from a Rails Blog that is working just
fine on row creation.
A large part of my purpose in using this particular model is to see how
far I can take Rails’ constructs. If it can’t handle my needs then I
will simply move on. So far, the only issues I have run into are in the
class of minor implementation tweaks (maturity) rather than baseline
design issues.