Getting a strange error when trying to output some data as a response to a j开发者_Go百科son request. For the life of me I cannot figure out the problem here. I am doing something very similar in another controller and not getting any error at all. Any ideas what would be causing this?
class SessionsController
...
user = User.authenticate(params[:session][:email].downcase,
params[:session][:password].downcase)
if user.nil?
respond_with(@error = "Invalid email/password combination.")
else
sign_in user
respond_with([user, user.authenticated_with])
end
-------------------------------------
User.rb
...
def authenticated_with
fb_hash = {:facebook => (!self.authentications.where("provider = ?", "facebook").empty? ? true : false)}
tw_hash = {:twitter => (!self.authentications.where("provider = ?", "twitter").empty? ? true : false)}
providers = [fb_hash, tw_hash]
return providers
end
-------------------------------------
LOG OUTPUT
2011-09-05T15:25:51+00:00 app[web.1]: NoMethodError (undefined method `model_name' for Array:Class):
2011-09-05T15:25:51+00:00 app[web.1]: app/controllers/sessions_controller.rb:24:in `create'
The log error is referencing this line:
respond_with([user, user.authenticated_with])
Any ideas???
Thanks!
My solution for anyone who finds this. I ended up rewriting
respond_with()
as a respond_to block:
respond_to do |format|
format.json { render :json => [user, user.authenticated_with]}
end
This solved the problem for me!
精彩评论