Hey Everybody, Thanks in advance for checking out my question.
I've got nested routes like so:
resources :users do
resources :avatars
end
And upon creating a user, I also create an avatar like so:
def create
@user = User.create(params[:user])
@avatar = Avatar.create(:user_id => @user)
# Send both User and Avatar object back
respond_with(@user,@avatar)
end
HOWEVER, upon making a server request that would create an inadequate User object (that should result in JSON response {error_key => ...}), rails gives me the following error:
ActionController::RoutingError (No route matches {:user_id=>#<User id: nil, name: nil, phone_number: "mcdkls", email: "fdsa@cmadksl", password_hash: nil, password_salt: nil, auth_token: nil, admin: false>, :action=>"show", :controller=>"avatars", :id=>#<Avatar id: 19, user_id: 1, created_at: "2011-05-20 01:52:22", updated_at: "2011-05-20 01:52:22">}):
app/controllers/users_controller.rb:13:in `create'
Seems like Rails is attempting to display HTML rather than JSON, but if I alter my controller like so:
def create
@user = User.create(params[:user])
@avatar = Avatar.create(:user_id => @user)
# Send both User and Avatar object back
respond_with(@user)
end
Rails returns for me a beautiful {name => "can't be blank"}. Any thoughts?
Thanks a million, Jared