2016-03-25 16 views
0

Denetleyicimde, kullanıcı yeni Fatura oluşturma isteğini gönderdiğinde form verilerini kaydederim. Ancak fatura sayfasında bir kez başka bir sayfaya gidemem çünkü oturum hala temizlenemedi. Aşağıda benim kodum vardı. i #session[:pending_invoice] = nil ile session temizlenir eğerRaylar oturumu engellemeyi engelleyin

def new 

     @invoice = Invoice.new 

     #post request from detail page to invoice along with variable from form 
     if request.post?  

      @invoice.booking_date = params[:datepicker] 
      @invoice.product_id = params["product-id"] 
      @invoice.variants = params[:variant] 

      #if user not signed in, user redirected to sign in page before  
      #continue to post invoice page with form data saved in session 
      if !user_signed_in? 
       session[:pending_invoice] = @invoice 
       return redirect_to new_user_session_path 

      end 

      #following for case where user already signed in before directed to 
      #invoice page 
      set_extra_params_for_new 
      @invoice_params = {} 
      @contact_detail_params = {} 

     else 

      #this is when user are from sign in page with session present. This is 
      #the code that make the issues where I cant navigate away to other 
      #pages until I cleared the session with session[:pending_invoice] = 
      #nil. 
      if (session[:pending_invoice].present?) && (session[:pending_invoice].instance_of? Invoice) 

       @invoice = session[:pending_invoice] 
       set_extra_params_for_new 

       @invoice_params = {} 

       @contact_detail_params = {} 

      else 
       #this code for params post request that comes from payment gateway. So 
       #all the data in invoice page is intact 
       @invoice.booking_date = params[:invoice][:booking_date] 
       @invoice.product_id = params[:invoice][:product_id] 
       @invoice.coupon_id = params[:invoice][:coupon_id] 
       @invoice.coupon_amounts = params[:invoice][:coupon_amounts] 
       @coupon_amounts_with_user_currency = params[:invoice][:coupon_amounts_with_user_currency] 
       @invoice.variants = params[:variant] 
       set_extra_params_for_new 

       @invoice_params = params[:invoice] 

       #session[:pending_invoice] = nil 

      end 
     end 

     set_invoice_currency_attributes(@invoice) 

     gon.invoice = @invoice 
     gon.real_total_with_currency = @invoice.real_total_with_currency 
     gon.real_total = @invoice.real_total 


    end 

Şimdi konular, kullanıcı alışkanlık sayfayı yenilemek mümkün. Bir hataya neden olur. Bu tür bir sorunu nasıl çözebilirim? Teşekkürler!!

cevap

0

Komut dosyanızdan neler olup bittiğini tam olarak anlayamıyorum ve üzgünüm, basit bir yanıt değildir.

new denetleyici eylemi, POST isteklerini normal olarak işlemez, form doldurulmasını sağlamak için bir istek isteğini işler. create eylemi form verilerini içeren POST'u işler.

POST sırasında olmayan formları oluşturmadan önce oturum açmanızı öneririm. Benim uygulamada
uygulama denetleyici hattını oluşturmak before_action :require_signin

ve

def require_signin 
    unless signed_in? 
     store_location 
     flash[:danger] = "You must be signed in to access this section" 
     redirect_to signin_url # halts request cycle 
    end 
end 

bu vardır yürekten tavsiye öğretici by Michael Hartl

dayanmaktadır, çok iyice signin'i ve oturum yönetimini kapsıyor.

Şansın en iyi hali

İlgili konular