Forum: Ruby on Rails last saved record not retrieving .

Posted by fahim patel (fahim_patel)
on 2012-11-03 12:48
(Received via mailing list)
Hi all,


from last 1 hour i am facing one problem.

I have written a code for creating  user and show them in index page 
after
save.

Code is working perfectly but on index page i am getting all record till
second last record saved, but i am not getting current  record which is
saved.

But in database my last record is saved successful.


But when i restart the server , than on index page all record come with 
the
last record .

I dont know why this all is happening ?
Code below


######## controller code
class AdminUsersController < ApplicationController
  def new
    @admin = AdminUser.new
  end

  def index
    @admins = AdminUser.all
  end

  def create
    @admin = AdminUser.new(params[:admin_user])
    if @admin.save

      redirect_to admin_users_path
    else
      render "new"
    end
  end
end

######## new view############
<%= form_for @admin do|f|%>

First Name
<%= f.text_field :first_name%>
<%= submit_tag"Create"%>
<% end %>
######## index view############
<%= @admins%>

##############model
nothing in model



Hope you all understand the problem .


Thanks

Regards
Fahim Babar Patel
Posted by Colin Law (Guest)
on 2012-11-03 12:50
(Received via mailing list)
On 3 November 2012 11:46, Fahim Patel <pafahim@gmail.com> wrote:
> second last record saved, but i am not getting current  record which is
> saved.
>
> But in database my last record is saved successful.
>
>
> But when i restart the server , than on index page all record come with the
> last record .
>
> I dont know why this all is happening ?

Have a look at the Rails Guide on debugging, it will show you
techniques that you can use to debug your code.

Colin
Posted by fahim patel (fahim_patel)
on 2012-11-03 13:41
(Received via mailing list)
On Saturday, November 3, 2012 5:20:35 PM UTC+5:30, Colin Law wrote:
> after
> the
> > last record .
> >
> > I dont know why this all is happening ?
>
> Have a look at the Rails Guide on debugging, it will show you
> techniques that you can use to debug your code.
>
> Colin
>

Hi Colin,

Thanks for reply.
I use pry.
I Debug the good , when i use binding.pry my index object select all 
records

but when i remove binding.pry and start to create new record than same
issue i am facing.

Last record is not coming

Thanks
Posted by Colin Law (Guest)
on 2012-11-03 14:30
(Received via mailing list)
On 3 November 2012 12:40, Fahim Patel <pafahim@gmail.com> wrote:
>> >
>> >
>
> Last record is not coming
Then use some of the other techniques of debugging - insert debug code
to print information about what is going on in the console for
example.  Print @admins.count for example in the controller index
action to try and tie down where the problem lies.  The first thing to
determine is whether it the view is not displaying the last record or
whether @admins does not include all the records.

Are you using the latest version of the database gem?  What is it?
Look in Gemfile.lock to find out.

Colin
Posted by fahim patel (fahim_patel)
on 2012-11-03 14:36
(Received via mailing list)
On Saturday, November 3, 2012 7:00:23 PM UTC+5:30, Colin Law wrote:
> >> >
> is
> >> > I dont know why this all is happening ?
> > I use pry.
> to print information about what is going on in the console for
> example.  Print @admins.count for example in the controller index
> action to try and tie down where the problem lies.  The first thing to
> determine is whether it the view is not displaying the last record or
> whether @admins does not include all the records.
>
> Are you using the latest version of the database gem?  What is it?
> Look in Gemfile.lock to find out.
>
>
I puts  @admins.count it give me correct counting on controller and when 
i
pass the object
to index view same thing is happening .
I am using Postgres and as you say i will delete Gemfile.lock and run 
the
bundle.

Hope for the best
Posted by fahim patel (fahim_patel)
on 2012-11-05 07:56
(Received via mailing list)
On Saturday, November 3, 2012 7:05:47 PM UTC+5:30, Fahim Patel wrote:
>> >> On 3 November 2012 11:46, Fahim Patel <paf...@gmail.com> wrote:
>> >> > Code is working perfectly but on index page i am getting all record
>> >> > the
>> > Hi Colin,
>> > Last record is not coming
>>
>>
>
Hi Colin,
Still facing a problem. Table count giving me accurate counting ,

but
@admins = AdminUser.all
give me records till last restart server.

I don't know why this all is happening ?
Posted by Colin Law (Guest)
on 2012-11-05 08:53
(Received via mailing list)
On 5 November 2012 06:54, Fahim Patel <pafahim@gmail.com> wrote:
>>> >
>>> >> > after
>>> >> >
>>> >> Colin
>>> > issue
>>>
>> Hope for the best
>
> I don't know why this all is happening ?

I asked what gem you are using for database access, you have not told
us.  Possibly best to post Gemfile, Gemfile.lock and databsae.yml
here.  Also tell us which version of ruby and which version of rails
and which operating system you are using.

Also please do not send me a copy of your emails, just send it to the
list.  I do not need two copies.  Thanks.

Colin
Posted by fahim patel (fahim_patel)
on 2012-11-05 13:55
(Received via mailing list)
On Monday, November 5, 2012 1:22:32 PM UTC+5:30, Colin Law wrote:
> >>>
> >>> >> > from last 1 hour i am facing one problem.
> which
> >>> >> > last record .
> >>> >
> >>> > Last record is not coming
> >>>
> >>>
> > I don't know why this all is happening ?
>
>
#######################Gem file.lock################################
GEM
  remote: https://rubygems.org/
  specs:
    RedCloth (4.2.9)
    actionmailer (3.2.4)
      actionpack (= 3.2.4)
      mail (~> 2.4.4)
    actionpack (3.2.4)
      activemodel (= 3.2.4)
      activesupport (= 3.2.4)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.1)
      rack (~> 1.4.0)
      rack-cache (~> 1.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.1.3)
    activemodel (3.2.4)
      activesupport (= 3.2.4)
      builder (~> 3.0.0)
    activerecord (3.2.4)
      activemodel (= 3.2.4)
      activesupport (= 3.2.4)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activeresource (3.2.4)
      activemodel (= 3.2.4)
      activesupport (= 3.2.4)
    activesupport (3.2.4)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    acts-as-taggable-on (2.3.3)
      rails (~> 3.0)
    addressable (2.3.2)
    albino (1.3.3)
      posix-spawn (>= 0.3.6)
    ansi (1.4.3)
    arel (3.0.2)
    bcrypt-ruby (3.0.1)
    blogit (0.5.0)
      RedCloth (>= 4.2.9)
      acts-as-taggable-on (>= 2.2.1)
      albino (>= 1.3.3)
      jquery-rails
      kaminari (>= 0.13.0)
      nokogiri (>= 1.5.0)
      redcarpet (>= 2.0.1)
    builder (3.0.4)
    cancan (1.6.8)
    capybara (1.1.3)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      selenium-webdriver (~> 2.0)
      xpath (~> 0.1.4)
    childprocess (0.3.6)
      ffi (~> 1.0, >= 1.0.6)
    chronic (0.6.7)
    chunky_png (1.2.6)
    client_side_validations (3.2.1)
    coderay (1.0.8)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.4.0)
    compass (0.12.2)
      chunky_png (~> 1.2)
      fssm (>= 0.2.7)
      sass (~> 3.1)
    compass-rails (1.0.3)
      compass (>= 0.12.2, < 0.14)
    cucumber (1.2.1)
      builder (>= 2.1.2)
      diff-lcs (>= 1.1.3)
      gherkin (~> 2.11.0)
      json (>= 1.4.6)
    cucumber-rails (1.3.0)
      capybara (>= 1.1.2)
      cucumber (>= 1.1.8)
      nokogiri (>= 1.5.0)
    database_cleaner (0.9.1)
    diff-lcs (1.1.3)
    em-websocket (0.3.8)
      addressable (>= 2.1.1)
      eventmachine (>= 0.12.9)
    email_spec (1.4.0)
      launchy (~> 2.1)
      mail (~> 2.2)
    erubis (2.7.0)
    eventmachine (1.0.0)
    execjs (1.4.0)
      multi_json (~> 1.0)
    factory_girl (4.1.0)
      activesupport (>= 3.0.0)
    factory_girl_generator (0.0.3)
    factory_girl_rails (4.1.0)
      factory_girl (~> 4.1.0)
      railties (>= 3.0.0)
    ffaker (1.15.0)
    ffi (1.1.5)
    friendly_id (4.0.9)
    fssm (0.2.9)
    gherkin (2.11.5)
      json (>= 1.4.6)
    growl (1.0.3)
    guard (1.5.3)
      listen (>= 0.4.2)
      lumberjack (>= 1.0.2)
      pry (>= 0.9.10)
      thor (>= 0.14.6)
    guard-livereload (1.1.0)
      em-websocket (>= 0.2.0)
      guard (>= 1.5.0)
      multi_json (~> 1.0)
    guard-rspec (2.1.1)
      guard (>= 1.1)
      rspec (~> 2.11)
    hike (1.2.1)
    hirb (0.7.0)
    i18n (0.6.1)
    journey (1.0.4)
    jquery-rails (2.1.3)
      railties (>= 3.1.0, < 5.0)
      thor (~> 0.14)
    json (1.7.5)
    kaminari (0.14.1)
      actionpack (>= 3.0.0)
      activesupport (>= 3.0.0)
    launchy (2.1.2)
      addressable (~> 2.3)
    libv8 (3.3.10.4)
    libwebsocket (0.1.5)
      addressable
    listen (0.5.3)
    lumberjack (1.0.2)
    mail (2.4.4)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    method_source (0.8.1)
    mime-types (1.19)
    mini_magick (3.4)
      subexec (~> 0.2.1)
    minitest (4.2.0)
    multi_json (1.3.7)
    nokogiri (1.5.5)
    pg (0.14.1)
    pg_search (0.5.7)
      activerecord (>= 3)
      activesupport (>= 3)
    polyglot (0.3.3)
    posix-spawn (0.3.6)
    pry (0.9.10)
      coderay (~> 1.0.5)
      method_source (~> 0.8)
      slop (~> 3.3.1)
    rack (1.4.1)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (3.2.4)
      actionmailer (= 3.2.4)
      actionpack (= 3.2.4)
      activerecord (= 3.2.4)
      activeresource (= 3.2.4)
      activesupport (= 3.2.4)
      bundler (~> 1.0)
      railties (= 3.2.4)
    rails3-jquery-autocomplete (1.0.10)
      rails (~> 3.0)
    railties (3.2.4)
      actionpack (= 3.2.4)
      activesupport (= 3.2.4)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)
    rake (0.9.2.2)
    rb-readline (0.4.2)
    rdoc (3.12)
      json (~> 1.4)
    recaptcha (0.3.4)
    redcarpet (2.2.2)
    rspec (2.11.0)
      rspec-core (~> 2.11.0)
      rspec-expectations (~> 2.11.0)
      rspec-mocks (~> 2.11.0)
    rspec-core (2.11.1)
    rspec-expectations (2.11.3)
      diff-lcs (~> 1.1.3)
    rspec-mocks (2.11.3)
    rspec-rails (2.11.4)
      actionpack (>= 3.0)
      activesupport (>= 3.0)
      railties (>= 3.0)
      rspec (~> 2.11.0)
    rubyzip (0.9.9)
    sass (3.2.2)
    sass-rails (3.2.5)
      railties (~> 3.2.0)
      sass (>= 3.1.10)
      tilt (~> 1.3)
    selenium-webdriver (2.26.0)
      childprocess (>= 0.2.5)
      libwebsocket (~> 0.1.3)
      multi_json (~> 1.0)
      rubyzip
    shoulda-matchers (1.4.1)
      activesupport (>= 3.0.0)
    simplecov (0.7.1)
      multi_json (~> 1.0)
      simplecov-html (~> 0.7.1)
    simplecov-html (0.7.1)
    sitemap_generator (3.4)
      builder
    slop (3.3.3)
    sprockets (2.1.3)
      hike (~> 1.2)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    subexec (0.2.2)
    therubyracer (0.10.2)
      libv8 (~> 3.3.10)
    thor (0.16.0)
    tilt (1.3.3)
    treetop (1.4.12)
      polyglot
      polyglot (>= 0.3.1)
    turn (0.9.6)
      ansi
    tzinfo (0.3.34)
    uglifier (1.3.0)
      execjs (>= 0.3.0)
      multi_json (~> 1.0, >= 1.0.2)
    whenever (0.7.3)
      activesupport (>= 2.3.4)
      chronic (~> 0.6.3)
    wicked (0.3.0)
      activesupport (>= 3.0.7)
      rails (>= 3.0.7)
    xpath (0.1.4)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  bcrypt-ruby
  blogit
  cancan
  capybara
  client_side_validations
  coffee-rails (~> 3.2.1)
  compass-rails
  cucumber-rails
  database_cleaner
  email_spec
  execjs
  factory_girl
  factory_girl_generator
  factory_girl_rails
  ffaker
  friendly_id (~> 4.0.1)
  growl
  guard-livereload
  guard-rspec
  hirb
  jquery-rails
  launchy
  mini_magick
  minitest
  pg
  pg_search
  pry
  rails (= 3.2.4)
  rails3-jquery-autocomplete
  rb-readline
  recaptcha
  rspec-rails
  sass-rails (~> 3.2.3)
  selenium-webdriver
  shoulda-matchers
  simplecov
  sitemap_generator
  therubyracer
  turn
  uglifier (>= 1.0.3)
  whenever
  wicked


OS  - Ubunto 11.10
Ruby version  -  ruby 1.9.2p290 (2011-07-09 revision 32553) 
[x86_64-linux]
Raills Version - rails 3.2.4

###################database yml###################3
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On Mac OS X with macports:
#   gem install pg --
--with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
development:
  adapter: postgresql
  database: app_development
  pool: 5
  username: app_app
  password: app
  encoding: utf8
  host: localhost

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: localhost
  #port: 5432

  # Schema search path. The server defaults to $user,public
  #schema_search_path: myapp,sharedapp,public

  # Minimum log levels, in increasing order:
  #   debug5, debug4, debug3, debug2, debug1,
  #   log, notice, warning, error, fatal, and panic
  # The server defaults to notice.
  #min_messages: warning

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
  adapter: postgresql
  encoding: utf8
  database: app_test
  pool: 5
  username: app_app
  password: app
  host: localhost

production:
  adapter: postgresql
  encoding: utf8
  database: app_production
  pool: 5
  username: app_app
  password: app
  host: localhost
cucumber:
  <<: *test
Posted by Colin Law (Guest)
on 2012-11-05 14:26
(Received via mailing list)
On 5 November 2012 12:54, Fahim Patel <pafahim@gmail.com> wrote:
> ...

All that looks ok to me, I am out of ideas.  Anyone else?

Colin
Posted by fahim patel (fahim_patel)
on 2012-11-05 14:32
(Received via mailing list)
I try to use sleep in index action controller before and after , but it
also not work.
One thing i notice is that after some time or restart server 
when,refresh
the page, all acurate object come on
index page.


But not after creation ?
Posted by fahim patel (fahim_patel)
on 2012-11-05 14:36
(Received via mailing list)
On Monday, November 5, 2012 7:00:53 PM UTC+5:30, Fahim Patel wrote:
>
>
> I try to use sleep in index action controller before and after , but it
> also not work.
> One thing i notice is that after some time or  , restart server  all
> acurate object come on
> index page.
>
After some time means when i work on other page which is not of same 
model
and controller.

Still but i have to restart the server for AdminUser module.

Dont know y this all is happening only with AdminUser module, other MVC
module are working perfectly
Posted by fahim patel (fahim_patel)
on 2012-11-20 15:29
fahim patel wrote in post #1082938:
> On Monday, November 5, 2012 7:00:53 PM UTC+5:30, Fahim Patel wrote:
>>
>>
>> I try to use sleep in index action controller before and after , but it
>> also not work.
>> One thing i notice is that after some time or  , restart server  all
>> acurate object come on
>> index page.
>>
> After some time means when i work on other page which is not of same
> model
> and controller.
>
> Still but i have to restart the server for AdminUser module.
>
> Dont know y this all is happening only with AdminUser module, other MVC
> module are working perfectly

Still facing problem ?
dont know ?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.