Hi!

The call to to_json shouldn't be the last call in the statement?

Regards,
Everaldo
On Tue, Nov 15, 2011 at 9:06 PM, John Merlino wrote:

this error usually occurs when trying to mix 1st and 2nd order
relationships in a single to_json call:

undefined method `macro' for nil:NilClass

Rails 3 has this way to support 2nd order relationships:

http://apidock.com/rails/ActiveRecord/Serialization/to_json

So I try to use it:

@units = User.where(:id =>
params[:user_id]).first.units.to_json(:include => {
:only => :reports,
:notifications => {:include => {:only
=> :notification_codes} }
})

A unit has many reports and notifications. And a notification belongs
to notification code.

This is the relationship between notifications and notification codes:

//notifications
belongs_to :notification_code, :foreign_key => :code

//notification codes
has_many :notifications

So I am not sure why error occurs.

Thanks for response

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

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 7 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 15, '11 at 11:19p
activeNov 18, '11 at 3:09p
posts7
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase