0

My app seems to randomly be throwing an error when users are trying to load grid data into the form:

   ActionView::Template::Error (undefined method `first_name' for nil:NilClass):
3:          t = @conts
4:                          xml.tag!("row",{ "id" => t.id }) do
5:
6:                                  xml.tag!("cell", t.first_name)
7:                                  xml.tag!("cell", t.last_name)
8:                          xml.tag!("cell", t.email)
9:                                  xml.tag!("cell", t.phone_1)

And following is the controller file

 def compdata
       @conts = Continfo.find_by_id(params[:id])
    end

Correspondence compdata RXML file

     xml.instruct! :xml, :version=>"1.0" 
       xml.tag!("rows") do
     t = @conts
        xml.tag!("row",{ "id" => t.id }) do

            xml.tag!("cell", t.first_name)
            xml.tag!("cell", t.last_name)
            xml.tag!("cell", t.email)
            xml.tag!("cell", t.phone_1)
            xml.tag!("cell", t.phone_2)
            xml.tag!("cell", t.homepage)
            xml.tag!("cell", t.skype)
    end
end

1 Answer 1

0

First item

It looks like you have a few other similar questions (here and here) open right now, and for both the current one and this one it looks like your @conts value is currently nil meaning nothing was brought back when it ran the search:

def compdata
  @conts = Continfo.find_by_id(params[:id])
end

Are you sure there is a value available in your table with the id equal to params[:id]?

If there is a mismatch there, that would be the first place I would look.

Second item

You may also run into an issue trying to call the method each on @conts because the find_by_id method will not bring back an array. If you want it to iterate over each record instead of each key/val, try using find_all_by_id which will return an array.

Third item

After looking at your other question, it looks like your syntax on this is different, but shouldn't you iterate over @conts again like this?

xml.tag!("rows") do
  @conts.each do |t|
    xml.tag!("row",{ "id" => t.id }) do
      xml.tag!("cell", t.first_name)
      xml.tag!("cell", t.last_name)
      xml.tag!("cell", t.email)
      xml.tag!("cell", t.phone_1)
      xml.tag!("cell", t.phone_2)
      xml.tag!("cell", t.homepage)
      xml.tag!("cell", t.skype)
    end
  end
end

This would be the way to assign t instead of like t = @conts, especially if you plan to step through many of them.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot and happy new year.. we have values in our table for ID, but still we are not able to load the data from grid to form. we have to build our application like this with out using php, here is our link please go through it,and tell me how to link grid with form to load the value to form, docs.dhtmlx.com/doku.php? id=tutorials:dhtmlx_today:gridlink
Is there a reason you are trying to do this with xml tags and all that? In rails, all of the forms and lists should be pre-built when you generate your scaffolding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.