0
因此,我正在創建一個簡單的引薦跟蹤系統。用戶將網址發佈給看起來像這樣的朋友http://localhost:3000/users/sign_up?referral=2。該引薦代碼然後在新用戶註冊中的隱藏輸入中使用,但我似乎無法將其保存。當我檢查頁面時,我可以看到該值,但不保存。另外,我以此爲指導。 http://www.ytutorial.com/tutorials/2-rails-referral-affiliate-trackingURL中未保存的參數
視圖/設計/註冊/ new.html.erb
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :role => 'form',
:class => 'payola-onestep-subscription-form',
'data-payola-base-path' => payola_path,
'data-payola-plan-type' => resource.plan.plan_class,
'data-payola-plan-id' => resource.plan.id}) do |f| %>
<%= f.hidden_field :referral_code, :as => :hidden, :input_html => { :value => session[:referral] } %>
應用程序/控制器/ application_controller.rb
before_filter :capture_referal
private
def capture_referal
session[:referral] = params[:referral] if params[:referral]
end
應用程序/控制器/ registrations_controller.rb
def sign_up_params
params.require(:user).permit(:email, :password, :password_confirmation, :plan_id, :size, :street1, :street2, :city, :state, :zip, :referral_code)
end
您使用的是simple_form_for嗎? – blnc
不,我更新了你的看法。 – DhatchXIX
<%= f.hidden_field:referral_code,:as =>:hidden,:input_html => {:value => session [:referral]}%>'應該是'<%= f.hidden_field:referral_code, value:session [:referral]%>' – dhouty