Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8458235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:01:28+00:00 2026-06-10T13:01:28+00:00

this is log from debugger when I run my PostsController spec on create action.

  • 0

this is log from debugger when I run my PostsController spec on create action. I’m not changing or manipulating any db records during runtime with console so this is no special case.

(rdb:1) p Post.last
#<Post id: 2, author_id: 3, title: "My ultra cool post", content: "Lorem ipsum", deleted_at: nil, created_at: "2012-08-31 09:21:20", updated_at: "2012-08-31 09:21:20", published_at: nil, display_from: nil>

(rdb:1) p Post.all
[#<Post id: 2, author_id: 3, title: "My ultra cool post", content: "Lorem ipsum", deleted_at: nil, created_at: "2012-08-31 09:21:20", updated_at: "2012-08-31 09:21:20", published_at: nil, display_from: nil>, 
 #<Post id: 3, author_id: 2, title: "My ultra cool post", content: "Lorem ipsum", deleted_at: nil, created_at: "2012-08-31 09:21:20", updated_at: "2012-08-31 09:21:20", published_at: nil, display_from: nil>]

(rdb:1) p Post.last
#<Post id: 2, author_id: 3, title: "My ultra cool post", content: "Lorem ipsum", deleted_at: nil, created_at: "2012-08-31 09:21:20", updated_at: "2012-08-31 09:21:20", published_at: nil, display_from: nil>

So Post.all shows that post 3 exist but Post.last not

but when I do

(rdb:1) p Post.all.last
#<Post id: 3, author_id: 2, title: "My ultra cool post", content: "Lorem ipsum", deleted_at: nil, created_at: "2012-08-31 09:21:20", updated_at: "2012-08-31 09:21:20", published_at: nil, display_from: nil>

Controller file:

class PostsController < ApplicationController
  def create
    @post.author = current_user
    @post.save
    debugger # this is where I'm debugging
    respond_with @post
  end
end
  • this behavior works in develompent code correctly

the only implication for me is that in my spec I’ll do

 response.should redirect_to Post.all.last

insted of

 response.should redirect_to Post.last

I know that in Ralis there are some cases where Active Record triggers call before DB is ready ? but in this case the ActiveRecord actually know about existance of this record with .all call but not with .last, so this is just weird

Any thoughts on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:01:29+00:00Added an answer on June 10, 2026 at 1:01 pm

    This behavior is quite logic: default order is based on created_at, and your objects both have the same created_at date time.

    So the database has to make a (random) choice.


    Actually, I just read dthe default order depends on the database you’re working with. To be sure you get what you expect use a default_scope, for instance:

    default_scope order('id ASC')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how to delete/remove call log from application. I am doing like this this.getContentResolver().delete(CallLog.Calls.CONTENT_URI,null,null); it
i'm querying a database like this: SELECT * from Log WHERE cookieId IN (select
I received >>> THIS <<< error log from a client. I replaced the app
I have this original formula from a medical research book: Log(e) (EFW) = (-4.564+(0.282*AC)-(0.00331*AC^2))*1000
I have a breakpoint action and am using the Log option from the drop
I have this code: function Keyboard() { this.log = $('#log')[0]; this.pressedKeys = []; this.bindUpKeys
I have set up a screen rc file like this: log on shelltitle apt
I have a table on my database called 'Log'. This Log table contains ID,
I'm analyzing an iOS 4 application for iPhone and I get this log: Leaked
Why is this: console.log(1100 ^ 0001) => 1101 // as expected console.log(1100 ^ 1001)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.