所以我有一個Rails應用程序2.x的應用程序,通過網絡工作正常,但試圖執行一個POST我不斷收到時,「重定向到停止http://localhost:3000/session/new過濾器鏈作爲[:require_user] rendered_or_redirected。「。在我的iPhone應用程序,我可以創造一個新的會話,並通過我的iPhone應用程序登錄的,但不能發佈說出POSTS_Controller。重定向到http://本地主機:3000 /會話/新
我有這個在我的代碼
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和有「啞劇:: Type.register_alias‘應用/ JSON’:JSON」建立在軌道側。
是否使用HTTP基本身份驗證您的用戶從cookie的方法是什麼?如果沒有,你需要。 – jamesc
就是這樣。 user = authenticate_with_http_basic do | login,password | User.authenticate(登錄名,密碼) 結束 會話[:USER_ID = user.id如果用戶 用戶 – jdog
:)高興你得到它排序 – jamesc