0

我試圖刪除我的Rails應用程序中的註冊/登錄要求,以便用戶進行預訂,但未能這樣做。我很新,我不確定我想做什麼其他更改,但錯過了,任何幫助將不勝感激,謝謝!Rails應用程序:允許用戶在未登錄的情況下進行購買

工作代碼(與註冊/登錄的要求)

class CourseController < ApplicationController 
     before_filter { @account_menu = :courses } 
     before_filter :authenticate_user!, :except => ['show', 'find', 'messages', 'chat_threads', 'new'] 

     before_filter lambda { 
     if current_profile.try(:learner?) 
      flash[:alert] = "You cannot access these pages" 
      redirect_to '/' 
     end 
     }, :only => [:new, :edit, :cancel, :start, :complete] 

     before_filter lambda { 
     if current_profile.teacher? 
      flash[:alert] = "You cannot access these pages" 
      redirect_to '/' 
     end 
     }, :only => [:book, :wish_list, :wish, :unwish, :cancel_booking, :pending] 

    layout 'account' 

    def book 
     @title = "Book a Course" 
     @course = Course.by_uid(params[:uid]) 

     if current_profile.learner? 
      if request.post? 
      price = params[:price].try(:to_f) || 0 
      current_profile.update_attributes({ :contact_email => params[:contact_email], :contact_phone => params[:contact_phone] }) 
      params['payment-option'] = 'learnlist' if price == 0 
      case params['payment-option'] 
       when 'learnlist' then 
       if current_user.balance >= price 
        current_user.transaction do 
        br = BookingRequest.create!({ 
                :course_id => @course.id, 
                :deposited_price => price, 
                :hourly_price => params[:hourly_price].try(&:to_f), 
                :lessons => params[:lessons] || [], 
                :end_of_base_period => params[:end_of_base_period], 
                :learner_id => current_profile.id, 
                :source => 'learnlist', 
                :comments_by_learner => params[:comments], 
                :place_to_come_by_learner => params[:place_to_come], 
                :attendance => params[:attendance], 
                :learner_username => params[:username], 
                :learner_video_chat_platform => params[:video_chat_platform], 
                :cancellation_commission => @course.cancellation_commission 
               }) 
        flash[:notice] = "Your booking request has been successfully sent to the teacher for confirmation" 
        Notification.add(@course.teacher.user, 'booking_request', br) 
        redirect_to course_path(@course.uid) 
        end 
       else 
        flash.now[:alert] = "You don't have enough funds in your account to book this course. You'll have to pay with PayPal to book the class" 
       end 
       when 'paypal' then 
       if !current_profile.paypal_set_up? || params[:paypal_email] != current_profile.paypal_email 
        result = Financials.paypal_preapproval(current_profile, params[:paypal_email], { :course => @course.uid, :price => price, :lessons => params[:lessons] || [], :end_of_base_period => params[:end_of_base_period], :hourly_price => params[:hourly_price].try(&:to_f) }) 
        if result 
        current_profile.update_attributes!({ 
                  :paypal_preapproval_id => result[:preapproval_id], 
                  :paypal_preapproval_confirmed_at => nil, 
                  :paypal_email => params[:paypal_email] 
                 }) 
        redirect_to result[:redirect_url] 
        else 
        flash.now[:alert] = "Could not setup PayPal payments. Payments preapproval could not be requested" 
        end 
       else 
        br = BookingRequest.create!({ 
                :course_id => @course.id, 
                :deposited_price => price, 
                :hourly_price => params[:hourly_price].try(&:to_f), 
                :lessons => params[:lessons] || [], 
                :end_of_base_period => params[:end_of_base_period], 
                :learner_id => current_profile.id, 
                :source => 'paypal', 
                :comments_by_learner => params[:comments], 
                :place_to_come_by_learner => params[:place_to_come], 
                :attendance => params[:attendance], 
                :learner_username => params[:username], 
                :learner_video_chat_platform => params[:video_chat_platform], 
                :cancellation_commission => @course.cancellation_commission, 
                :learnlist_partial_funding => params[:learnlist_partial].try(:to_i) == 1 
               }) 
        Notification.add(@course.teacher.user, 'booking_request', br) 
        flash[:notice] = "Booking successfully submitted" 
        redirect_to course_path(@course.uid) 
       end 
       when 'braintree' then 
       if params[:payment_method_nonce].blank? 
        flash.now[:alert] = 'You did not configure your payment method. Please click Configure and set it up to proceed' 
       else 
        br = BookingRequest.create!({ 
                :course_id => @course.id, 
                :deposited_price => price, 
                :hourly_price => params[:hourly_price].try(&:to_f), 
                :lessons => params[:lessons] || [], 
                :end_of_base_period => params[:end_of_base_period], 
                :learner_id => current_profile.id, 
                :source => 'braintree', 
                :comments_by_learner => params[:comments], 
                :place_to_come_by_learner => params[:place_to_come], 
                :attendance => params[:attendance], 
                :learner_username => params[:username], 
                :learner_video_chat_platform => params[:video_chat_platform], 
                :braintree_payment_method_nonce => params[:payment_method_nonce], 
                :cancellation_commission => @course.cancellation_commission, 
                :learnlist_partial_funding => params[:learnlist_partial].try(:to_i) == 1 
               }) 
        Notification.add(@course.teacher.user, 'booking_request', br) 
        flash[:notice] = "Booking successfully submitted" 
        redirect_to course_path(@course.uid) 
       end 
      end 
      end 
     else 
      flash[:alert] = "You cannot access this view" 
      redirect_to '/' 
     end 
     end 

我試圖刪除要求註冊/登錄如下所示。我沒有做到這一點,因爲點擊書籍按鈕將我帶回主頁而不是書籍視圖。

class CourseController < ApplicationController 
    before_filter { @account_menu = :courses } 
    before_filter :authenticate_user!, :except => ['show', 'find', 'messages', 'chat_threads', 'new', 'book'] 

    before_filter lambda { 
    if current_profile.try(:learner?) 
     flash[:alert] = "You cannot access these pages" 
     redirect_to '/' 
    end 
    }, :only => [:new, :edit, :cancel, :start, :complete] 

    before_filter lambda { 
    if current_profile.try(:teacher?) 
     flash[:alert] = "You cannot access these pages" 
     redirect_to '/' 
    end 
    }, :only => [:book, :wish_list, :wish, :unwish, :cancel_booking, :pending] 

    layout 'account' 

def book 
    @title = "Book a Course" 
    @course = Course.by_uid(params[:uid]) 

     if request.post? 
     price = params[:price].try(:to_f) || 0 
     current_profile.update_attributes({ :contact_email => params[:contact_email], :contact_phone => params[:contact_phone] }) 
     params['payment-option'] = 'learnlist' if price == 0 
     case params['payment-option'] 
      when 'learnlist' then 
      if current_user.balance >= price 
       current_user.transaction do 
       br = BookingRequest.create!({ 
               :course_id => @course.id, 
               :deposited_price => price, 
               :hourly_price => params[:hourly_price].try(&:to_f), 
               :lessons => params[:lessons] || [], 
               :end_of_base_period => params[:end_of_base_period], 
               :learner_id => current_profile.id, 
               :source => 'learnlist', 
               :comments_by_learner => params[:comments], 
               :place_to_come_by_learner => params[:place_to_come], 
               :attendance => params[:attendance], 
               :learner_username => params[:username], 
               :learner_video_chat_platform => params[:video_chat_platform], 
               :cancellation_commission => @course.cancellation_commission 
              }) 
       flash[:notice] = "Your booking request has been successfully sent to the teacher for confirmation" 
       Notification.add(@course.teacher.user, 'booking_request', br) 
       redirect_to course_path(@course.uid) 
       end 
      else 
       flash.now[:alert] = "You don't have enough funds in your account to book this course. You'll have to pay with PayPal to book the class" 
      end 
      when 'paypal' then 
      if !current_profile.paypal_set_up? || params[:paypal_email] != current_profile.paypal_email 
       result = Financials.paypal_preapproval(current_profile, params[:paypal_email], { :course => @course.uid, :price => price, :lessons => params[:lessons] || [], :end_of_base_period => params[:end_of_base_period], :hourly_price => params[:hourly_price].try(&:to_f) }) 
       if result 
       current_profile.update_attributes!({ 
                 :paypal_preapproval_id => result[:preapproval_id], 
                 :paypal_preapproval_confirmed_at => nil, 
                 :paypal_email => params[:paypal_email] 
                }) 
       redirect_to result[:redirect_url] 
       else 
       flash.now[:alert] = "Could not setup PayPal payments. Payments preapproval could not be requested" 
       end 
      else 
       br = BookingRequest.create!({ 
               :course_id => @course.id, 
               :deposited_price => price, 
               :hourly_price => params[:hourly_price].try(&:to_f), 
               :lessons => params[:lessons] || [], 
               :end_of_base_period => params[:end_of_base_period], 
               :learner_id => current_profile.id, 
               :source => 'paypal', 
               :comments_by_learner => params[:comments], 
               :place_to_come_by_learner => params[:place_to_come], 
               :attendance => params[:attendance], 
               :learner_username => params[:username], 
               :learner_video_chat_platform => params[:video_chat_platform], 
               :cancellation_commission => @course.cancellation_commission, 
               :learnlist_partial_funding => params[:learnlist_partial].try(:to_i) == 1 
              }) 
       Notification.add(@course.teacher.user, 'booking_request', br) 
       flash[:notice] = "Booking successfully submitted" 
       redirect_to course_path(@course.uid) 
      end 
      when 'braintree' then 
      if params[:payment_method_nonce].blank? 
       flash.now[:alert] = 'You did not configure your payment method. Please click Configure and set it up to proceed' 
      else 
       br = BookingRequest.create!({ 
               :course_id => @course.id, 
               :deposited_price => price, 
               :hourly_price => params[:hourly_price].try(&:to_f), 
               :lessons => params[:lessons] || [], 
               :end_of_base_period => params[:end_of_base_period], 
               :learner_id => current_profile.id, 
               :source => 'braintree', 
               :comments_by_learner => params[:comments], 
               :place_to_come_by_learner => params[:place_to_come], 
               :attendance => params[:attendance], 
               :learner_username => params[:username], 
               :learner_video_chat_platform => params[:video_chat_platform], 
               :braintree_payment_method_nonce => params[:payment_method_nonce], 
               :cancellation_commission => @course.cancellation_commission, 
               :learnlist_partial_funding => params[:learnlist_partial].try(:to_i) == 1 
              }) 
       Notification.add(@course.teacher.user, 'booking_request', br) 
       flash[:notice] = "Booking successfully submitted" 
       redirect_to course_path(@course.uid) 
      end 
     end 
     end 
    else 
     flash[:alert] = "You cannot access this view" 
     redirect_to '/' 
    end 

對不起,如果需要更多的信息,我會很樂意重新裝修。

回答

1

處理此問題的標準方式是爲創建該用戶的用戶帳戶,沒有任何個人詳細信息,但保留它們「登錄」到此用戶帳戶。通過這種方式,他們可以在頁面上持久化,可以填滿他們的籃子,稍後再回到同一臺計算機等。

後來,當您真正需要他們的個人詳細信息時,可以說「在我們進入下一步之前,您需要寄存器」。然後,您可以將個人詳細信息添加到您之前爲其創建的帳戶中,然後執行電子郵件驗證或任何您想要執行的操作。

通過這種方法,您最終會得到大量「不完整」的用戶帳戶,而這些用戶從不打算註冊,而且您可以安排一個計劃任務來刪除所有超過一週的用戶帳戶例。

+0

謝謝您的輸入!比方說,我不需要頁面和任何籃子的持久性,而是點擊「預訂」時,它會將用戶帶到預訂頁面,該頁面也將用作註冊表單,我該如何去做這件事? – ttinggggg

+0

Cookies:將預訂的詳細信息保存在Cookie中,或將預訂保存到數據庫,然後將預訂的數據庫ID保存在cookie中。 –

+0

我明白了,一定會找到答案,謝謝您的幫助! – ttinggggg

相關問題