计划ID未以Devise形式分配。导轨

时间:2015-08-21 06:41:57

标签: ruby-on-rails forms ruby-on-rails-4 devise rails-console

我有一个Rails个应用,主页上有3个注册按钮链接  每个人都有自己的计划分配给它。其中两个转到基本表单,而第三个转到带有信用卡详细信息的表单,由Stripe处理。表单和用户由Devise处理。

计划似乎设置正确并且在rails console中可见,但是当我转到sign up时,他们中的任何一个都只捕获了电子邮件地址和密码,并且没有{{{ 1}}已分配。

我注意到在本地预览表单页面时,顶部的url不会更改为特定的表单url,例如plan_id,而是显示表单但保留在{{1我很困惑,因为服务器似乎认识到我点击了哪个链接以及需要分配哪个计划?请帮助!!

/users/sign_up?plan=3

在154ms完成200 OK(浏览次数:151.7ms | ActiveRecord:0.0ms)

console User.last

homepage url?

这是我的application_controller.rb

Started GET "/users/sign_up?plan=3" for 124.149.46.152 at 2015-08-21 06:32:19 +0000
Cannot render console from 124.149.46.152! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Users::RegistrationsController#new as HTML
  Parameters: {"plan"=>"3"}
  Rendered devise/registrations/_paid.html.erb (8.1ms)
  Rendered devise/shared/_links.html.erb (0.3ms)
  Rendered devise/registrations/new.html.erb within layouts/application (11.6ms)

开发日志

=> #<User id: 7, email: "testemail1@test.com", encrypted_password: "$2a$10$.EldkZ3KUdnz4u1dvIMkXO7U6GnAnrGNYomdITKqup....", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2015-08-21 07:05:34", last_sign_in_at: "2015-08-21 07:05:34", current_sign_in_ip: "124.149.46.152", last_sign_in_ip: "124.149.46.152", created_at: "2015-08-21 07:05:34", updated_at: "2015-08-21 07:05:34", plan_id: nil, stripe_customer_token: nil> 

/registrations_controller.rb

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_filter :configure_permitted_parameters, if: :devise_controller?

  protected
    def configure_permitted_parameters
      devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :stripe_card_token, :email, :password, :password_confirmation }
    end
end

1 个答案:

答案 0 :(得分:1)

要允许保存plan_id,您需要在设计注册参数中添加它。您可以通过在应用程序控制器中添加以下内容来完成此操作

before_filter :configure_permitted_parameters, if: :devise_controller?

def configure_permitted_parameters
   devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password_confirmation, :plan_id) }
end