来自 URL 的参数未保存在数据库中

Parameter from URL not saving in DB

所以我正在创建一个简单的推荐跟踪系统。用户将 post url 发给看起来像这样的朋友 http://localhost:3000/users/sign_up?referral=2. That referral code is then used in a hidden input within the new users signup, but I can't seem to get it to save. I can see the value when i inspect the page, but doesnt save. Also, I used this as a guide. http://www.ytutorial.com/tutorials/2-rails-referral-affiliate-tracking

views/devise/registration/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] } %>

app/controllers/application_controller.rb

before_filter :capture_referal
private
def capture_referal
  session[:referral] = params[:referral] if params[:referral]
end

app/controllers/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

使用默认表单生成器的隐藏字段标记的语法是

<%= f.hidden_field :referral_code, value: session[:referral] %>