所以我有一个rails app 2.x应用程序,可以通过网络正常工作,但在尝试执行POST时,我不断“重定向到http://localhost:3000/session/new过滤器链停止为[:require_user] rendered_or_redirected。”。在我的iPhone应用程序中,我可以创建一个新会话并通过我的iPhone应用程序登录,但无法POST来说出POSTS_Controller。
我的代码中有这个
Posts_Controller
before_filter :require_user, :only => [:create, :update, :destroy]
Application_Controller
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
include AuthenticatedSystem
include Geokit::Geocoders
helper :all # include all helpers, all the time
#session :session_key => '_cwa_session_id'
#filter_parameter_logging :password
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery # :secret => 'eejj7eded74769099999944a729b4f'
#filter_parameter_logging(:password)
before_filter :login_from_cookie
before_filter :find_user_interests
before_filter :find_user_posts
protected
def find_user_interests
@user_interests = cur_user ? cur_user.interesting_posts : []
logger.debug "User interests hash: #{current_user.inspect}"
end
def find_user_posts
@user_posts = cur_user ? cur_user.posts : []
end
def cur_user
User.find(session[:user_id]) if session[:user_id]
end
def require_user
unless cur_user
flash[:error] = "You must be logged in to do that."
redirect_to '/session/new'
return false
end
end
geocode_ip_address
def geokit
@location = session[:geo_location]
end
end
我已经为此工作了2个月,无法弄清楚这个问题。在我的iPhone应用程序中,我使用的是ObjectiveResource。我发送过json并在“rails”上设置了“Mime :: Type.register_alias”应用程序/ json“,:json”。
答案 0 :(得分:0)
我不是rails开发人员,但require_user的before过滤器无法通过cur_user测试,因为在会话哈希中找不到:user_id。您确定在使用iPhone时会有持续的会话吗?您是否正在使用设计进行身份验证?只是为了踢,如果您手动将user_id作为params传递,它是否有效?