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.
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.
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).