I encounter strange behavior in my controllers. It seems like they sometimes want to redirect rather than give a json response.
respond_to :json, :html, :js def create @favorite = current_user.favorites.build(:location_id=>params[:location_id]) if @favorite.save respond_with(@favorite) else respond_with(@favorite.errors) end end
I think it works most of the time, but today I received a notification about this error:
NoMethodError: undefined method `` favorite_url '' for # <FavoritesController: 0x00000006171dc0>
The params hash was registered as:
{"format"=>"json", "action"=>"create", "user_id"=>"56", "auth_token"=>"iGSty8CMIaWsbShYZEtw", "location_id"=>"47943", "controller"=>"favorites"}
Particularly strange since it works most of the time ... I changed some of my other controllers to use the old format.json syntax {render: json => @object}, but I would like to avoid it if possible.
How could this be?
source share