Why is rails using DB objects that don't exist?

I admit it–I’m newb right now. But only to rails, ruby and friends.
I’m walking through a “recipe” tutorial but have been stuck for hours;
it’s time to ask for help. On Windows I’ve got the latest ruby, rails,
and webrick; I’ve got the Oracle OCI “thing” to talk to our Oracle 10g
database, I’ve got Slick Edit and a command line.

I’ve created a recipes table, a sequence to feed its ID primary key
column, and a trigger that gets fired before record creation. I can use
sql at a command line in Oracle’s sqlplus to add records. No sweat.
But in the browser I get:

ActiveRecord::StatementInvalid in RecipeController#create

OCIError: ORA-02289: sequence does not exist: select recipes_seq.nextval
id from dual

I did once have a sequence with that name, but that’s long gone. In
fact I’ve dropped and recreated the table, sequence and trigger several
times with new names (except I continue using “recipes” for the table
name).

I’ve closed and opened and closed firefox. I’ve restarted webrick.

I’m having trouble imagining what’s up–because I believe this little
ruby app isn’t looking into the details of how an incrementing field
works. There are clearly remnants somewhere, I just can’t find them.

WTF?!

Thanks anyone for getting me back on track.

Although I’m not using oracle, I suspect that rails is using
standardized names to generate the sql to generate the recipe PK.

…so I’d suggest creating a sequence “recipes_seq” - rails likely
takes table name + ‘_seq’, and runs your quoated sql to obtain a pk
before doing an insert into recipes.

Jodi

Jodi S. wrote:

Although I’m not using oracle, I suspect that rails is using
standardized names to generate the sql to generate the recipe PK.

…so I’d suggest creating a sequence “recipes_seq” - rails likely
takes table name + ‘_seq’, and runs your quoated sql to obtain a pk
before doing an insert into recipes.

Jodi

That makes outstanding sense. I have written pretty much no code so
I’m clueless what the sql looks like. Is there a means for me to see
that? That would make this less magical, but also more comprehensible.
:wink:

And thanks for your reply.

Frank Burleigh wrote:

Jodi S. wrote:

Although I’m not using oracle, I suspect that rails is using
standardized names to generate the sql to generate the recipe PK.

…so I’d suggest creating a sequence “recipes_seq” - rails likely
takes table name + ‘_seq’, and runs your quoated sql to obtain a pk
before doing an insert into recipes.

Jodi

That makes outstanding sense. I have written pretty much no code so
I’m clueless what the sql looks like. Is there a means for me to see
that? That would make this less magical, but also more comprehensible.
:wink:

And thanks for your reply.

http://api.rubyonrails.com/

Rails, by default, guesses at the name of the sequence, as described by
the previous replier. To set the name of the sequence

class Recipe< ActiveRecord::Base
set_sequence_name “recipeseq” # default would have been “recipe_seq”
end

Rails uses conventions for a lot of these things, such as table names,
column names, sequences, etc. If you name your things like Rails
expects, you don’t ahve to do anything else. However, if you don’t,
that’s not a problem. You just have to tell rails what they are called.

For a class Recipe, rails assumes the tables name is loads. For all
tables, it assumed the primary key is a column called id. However, you
can tell it differently.

Class Recipe < ActiveRecord::Base
set_table_name “recipe”
set_primary_key “recipe”
end

If your table was recipe with a primary key called recipe, you can just
tell it that. That’s what I do to use ActiveRecord with the database
for a project at work, where the schema is 10 years old and
pre-existing.

you can see the sql, as it runs, in the log/development.log. (useful
for tuning as well)

As noted, the books are really worthwhile. AWD, recipes, etc.

have fun!
Jodi

Frank Burleigh wrote:

Jodi S. wrote:

Although I’m not using oracle, I suspect that rails is using
standardized names to generate the sql to generate the recipe PK.

…so I’d suggest creating a sequence “recipes_seq” - rails likely
takes table name + ‘_seq’, and runs your quoated sql to obtain a pk
before doing an insert into recipes.

Jodi

That makes outstanding sense. I have written pretty much no code so
I’m clueless what the sql looks like. Is there a means for me to see
that? That would make this less magical, but also more comprehensible.
:wink:

And thanks for your reply.

Agile Web D. with Rails is the gold standard for Rails books.
It’s absolutely outstanding, and in addition to being tremendously
informative, it’s also fairly interesting to boot. If you are doing any
Rails work at all, it’s a non-optional purchase.

http://www.pragmaticprogrammer.com/titles/rails/index.html