Hello comrades ,

I got a error. I don't understand that exception. What happened ?

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

i written this code:
if @personal_information.save
HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0']) # This line
is may a error.
hzs = HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0'])
hzs.personal_information_id = @personal_information.id
hzs.save

MODEL:

class PersonalInformation < ActiveRecord::Base
has_many :hamtran_zeeldegchs,:foreign_key => 'personal_information_id' ,
:class_name => 'HamtranZeeldegchs', :dependent => :destroy

class HamtranZeeldegchs < ActiveRecord::Base
belongs_to :personal_information , :class_name => 'PersonalInformation',
:foreign_key => ':personal_information_id'

Can anyone help me ?

-------------
Thanks
Tsolmon

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Mathew Vivek at Sep 24, 2011 at 1:11 pm
    hi,

    could you tell me the line you got error ?

    it sounds like u r going a add a HamtranZeeldegchs row.

    if @personal_information.save
    HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0']) # This
    line
    is may a error.
    hzs = HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0'])
    hzs.personal_information_id = @personal_information.id
    hzs.save



    -------------------------

    in create action.
    include the line p params in the beginnig and debug the params that
    are coming to this create action

    and you can save it hzs.personal_information_id = specific param

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Tsolmon Narantsogt at Sep 26, 2011 at 8:32 am
    if @personal_information.save
    yes this line --> HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0'])
    # This

    exception is:
    NoMethodError in Personal informationsController#create You have a nil
    object when you didn't expect it! You might have expected an instance of
    ActiveRecord::Base. The error occurred while evaluating nil.[]

    RAILS_ROOT: /home/tsolmon/workspace/Online
    Application Trace
    <http://localhost:3000/personal_informations/create#> | Framework
    Trace <http://localhost:3000/personal_informations/create#> | Full
    Trace<http://localhost:3000/personal_informations/create#>

    /home/tsolmon/workspace/Online/app/controllers/personal_informations_controller.rb:44:in
    `create'



    On Sat, Sep 24, 2011 at 9:11 PM, Mathew Vivek wrote:

    hi,

    could you tell me the line you got error ?

    it sounds like u r going a add a HamtranZeeldegchs row.

    if @personal_information.save
    HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0']) # This
    line
    is may a error.
    hzs = HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0'])
    hzs.personal_information_id = @personal_information.id
    hzs.save



    -------------------------

    in create action.
    include the line p params in the beginnig and debug the params that
    are coming to this create action

    and you can save it hzs.personal_information_id = specific param

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Sep 26, 2011 at 8:48 am

    On 26 September 2011 09:32, Tsolmon Narantsogt wrote:
    if @personal_information.save
    yes this line  --> HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0'])
    # This

    exception is:

    NoMethodError in Personal informationsController#create

    You have a nil object when you didn't expect it! You might have expected an
    instance of ActiveRecord::Base. The error occurred while evaluating nil.[]

    RAILS_ROOT: /home/tsolmon/workspace/Online

    Application Trace | Framework Trace | Full Trace

    /home/tsolmon/workspace/Online/app/controllers/personal_informations_controller.rb:44:in
    `create'
    Have a look at the Rails Guide on debugging. There you will find
    methods for debugging your code. In particular you could use
    ruby-debug to break into your code before that line and check that the
    data are ok.

    Colin


    On Sat, Sep 24, 2011 at 9:11 PM, Mathew Vivek wrote:

    hi,

    could you tell me the line you got error ?

    it sounds like u r going a add a HamtranZeeldegchs row.

    if @personal_information.save
    HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0'])   # This
    line
    is may a error.
    hzs = HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0'])
    hzs.personal_information_id = @personal_information.id
    hzs.save



    -------------------------

    in create action.
    include the line p params in the beginnig and debug the params that
    are coming to this create action

    and you can save it hzs.personal_information_id = specific param

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    gplus.to/clanlaw

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Jim Ruther Nill at Sep 24, 2011 at 3:58 pm

    On Sat, Sep 24, 2011 at 8:56 PM, Tsolmon Narantsogt wrote:

    Hello comrades ,

    I got a error. I don't understand that exception. What happened ?

    You have a nil object when you didn't expect it!
    You might have expected an instance of ActiveRecord::Base.
    The error occurred while evaluating nil.[]

    i written this code:
    if @personal_information.save
    HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0']) # This line
    is may a error.
    If this line is what's causing the error, then it means that
    params[:hamtran_zeeldegch] is nil.
    So calling params[:hamtran_zeeldegch]['0'] would cause the error.

    hzs = HamtranZeeldegchs.new(params[:hamtran_zeeldegch]['0'])
    hzs.personal_information_id = @personal_information.id
    hzs.save

    MODEL:

    class PersonalInformation < ActiveRecord::Base
    has_many :hamtran_zeeldegchs,:foreign_key => 'personal_information_id' ,
    :class_name => 'HamtranZeeldegchs', :dependent => :destroy

    class HamtranZeeldegchs < ActiveRecord::Base
    belongs_to :personal_information , :class_name => 'PersonalInformation',
    :foreign_key => ':personal_information_id'

    Can anyone help me ?

    -------------
    Thanks
    Tsolmon

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.


    --
    -------------------------------------------------------------
    visit my blog at http://jimlabs.heroku.com

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedSep 24, '11 at 12:56p
activeSep 26, '11 at 8:48a
posts5
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase