egervari
2011-May-27 17:26 UTC
How do you include json attributes when using "respond_with"?
I have a controller action that returns JSON data. def create @comment = @site_update.comments.new @comment.attributes = params[:comment] @comment.author = current_user if @comment.save respond_with @comment, :include => :author else respond_with @comment.errors end end This is obviously not working. How can I include the :author of the comment with the respond_with method? Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
egervari
2011-May-27 17:49 UTC
Re: How do you include json attributes when using "respond_with"?
Actually, it is working.... my bad... the problem is something else. For some reason, it''s trying to find ''comment_url'', but this does not exist because comment is a nested resource of another model. I''ll have to look at how to stop it from trying to find a url - it''s just not required here. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
egervari
2011-May-27 17:52 UTC
Re: How do you include json attributes when using "respond_with"?
To those having the same with problem with nested resources, this is the solution: def create @comment = @site_update.comments.new @comment.attributes = params[:comment] @comment.author = current_user if @comment.save respond_with @site_update, @comment, :include => :author else respond_with @site_update, @comment.errors end end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.