2

My user visits an item show view and then is send to the signup-page (I use devise). On the signup page, I have the params (item_id) of the item he visited on the previous page. I want this item_id to be saved when the user makes his sign_up (like user.item_id). Here is how I tried to do it:

<input value="#{params[:item_id]}" type="hidden" name="user[item_id]" id="user_item_id">

When the user is saved, the item_id remains empty. What am I missing here? Here is what I put into my controller:

def configure_sign_up_params
    devise_parameter_sanitizer.permit(:sign_up, keys: [:item_id])
end
Sabrina
  • 309
  • 1
  • 14

2 Answers2

3

Here is how I fixed it:

class RegistrationsController < Devise::RegistrationsController
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:item_id])
  end
end
BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
Sabrina
  • 309
  • 1
  • 14
0

How you handling this in controller. Just sending a parameter won't solve your issue

  • I edited my inital post with my controller. I got the controller code from this thread that I found: https://stackoverflow.com/questions/42572124/adding-custom-parameters-to-devise-registration-unpermitted-parameters – Sabrina May 28 '19 at 13:45