2011-08-05 19 views
0

にリダイレクトされているので、Web経由でうまく動作するレールアプリ2.xアプリを持っていますが、POSTを実行しようとすると "012にリダイレクトされ続けます。 [:require_user] rendered_or_redirected "としてください。"私のiPhoneアプリでは、私のiPhoneアプリで新しいセッションとサインインを作成できますが、POSTではPOSTS_Controllerと言うことはできません。http:// localhost:3000/session/new

は、私は2ヶ月間、これに取り組んできたと問題を把握することはできません

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 

私のコードでこれを持っています。私のiPhoneアプリでObjectiveResourceを使用しています。私はjsonを介して送信しており、 "Mime :: Type.register_alias" application/json "、:json"がレール側に設定されています。

+0

ログインからcookieメソッドでhttp基本認証を使用していますか?あなたがする必要がない場合。 – jamesc

+0

それはそれでした。 user = authenticate_with_http_basic do |ログイン、パスワード| ユーザー エンド セッション[:user_id] = user.id(ユーザーの場合) ユーザー – jdog

+0

:)嬉しいです。 – jamesc

答えて

0

私はレール開発者ではありませんが、require_userのbeforeフィルタは、セッションハッシュのuser_idを見つけることができないというcur_userテストに合格できません。 iPhoneを使用してもセッションが継続することは確かですか?認証にdeviseを使用していますか?ちょうどキックのために、手動でuser_idをparamsとして渡すとうまくいくのですか?

+0

いいえ、安静な認証を使用しています – jdog

関連する問題