Hi everyone, Thanks in advance for checking out my question.
I have nested routes:
resources :users do resources :avatars end
And when creating the user, I also create an avatar:
def create @user = User.create(params[:user]) @avatar = Avatar.create(:user_id => @user)
HOWEVER, after requesting a server that will create an inadequate User object (which should lead to a JSON response {error_key => ...}), the rails give 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'
It looks like Rails is trying to render HTML, not JSON, but if I change my controller like this:
def create @user = User.create(params[:user]) @avatar = Avatar.create(:user_id => @user)
Rails returns a beautiful {name => "cannot be empty"} for me. Any thoughts?
Thanks a million, Jared