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

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs