newbie, needs help, can someone explain

Sometimes when i am trying to use an instance variable in my view, which
is created in my controller, the value for the :id when passing as part
of the URL, just appears as an obscure number 23743276

is there a standard format to format this so it appears as the value in
the DB.

i dont understand how this works?

Brad Symons wrote:

Sometimes when i am trying to use an instance variable in my view, which
is created in my controller, the value for the :id when passing as part
of the URL, just appears as an obscure number 23743276

is there a standard format to format this so it appears as the value in
the DB.

i dont understand how this works?

for instance

this @testrun = Testrun.find_all_by_id(:last)

in the view im referencing is by: @testrun.id

it should be 916 in the db, but it just appears as 3765348

???

You are calling the method find_all which returns a collection not an
object. Leave out the all part. Also find_by_id is the default
behavior of find so you can just type in Testrun.find(:last) or
another shortcut, just Testrun.last.

Brad -

ActiveRecord::RecordNotFound in VersionController#show
Couldn't find Testrun with ID=last

error when using Testrun.find(:last)

when i used find_by_sql("SELECT MAX(id) FROM TESTRUNS")

I get

Testun328976%340ioh4%nrklh%Testrun38588y3%.... ... ....

If i use first it works fine and displays the first id in the table.

does it matter which version of rails im using, im using aptana running
instant rails.

would that affect this?

Brad -

learc wrote:

Also find_by_id is the default
behavior of find so you can just type in Testrun.find(:last) or
another shortcut, just Testrun.last.

This is incorrect. find_by_id is *not* the same as find. If you call
find for a non-existent id, Rails will raise an
ActiveRecord::RecordNotFound error, whereas find_by_id will just return
a nil. With find_by_id, you can do things like:

person = Person.find_by_id(params[:id]) || Person.new

I use that style to share code between :create and :update actions
(where appropriate).

Peace,
Phillip