ruby on rails - Custom devise controller not working -
i have 2 models resident , user. both of them contains roll_number attribute, have entered data in resident model want, when user register devise resource checks if resident there of same roll_number in resident model? , user can registered !! added attribute (roll_number) devise's user model, edited create method of registrations controller here's code of :
class users::registrationscontroller < devise::registrationscontroller before_action :configure_sign_up_params, only: [:create] before_action :configure_account_update_params, only: [:update] # /resource/sign_up # def new # super # end def create super resident = resident.find_by(roll_number: params[:roll_number]) if resident.present? @user = resident.create_user(params) if @user.save flash[:info] = "welcome messpay" redirect_to root_url else render 'new' end else flash[:danger] = "you have entered worng roll number or not resident" redirect_to new_user_registration end end # /resource/edit # def edit # super # end # put /resource # def update # super # end # delete /resource # def destroy # super # end # /resource/cancel # forces session data expired after sign # in expired now. useful if user wants # cancel oauth signing in/up in middle of process, # removing oauth session data. # def cancel # super # end # protected def configure_sign_up_params devise_parameter_sanitizer.permit(:sign_up, keys: [:roll_number,:resident_id]) end # if have params permit, append them sanitizer. def configure_account_update_params devise_parameter_sanitizer.permit(:account_update, keys: [:roll_number,:resident_id]) end # path used after sign up. # def after_sign_up_path_for(resource) # super(resource) # end # path used after sign inactive accounts. # def after_inactive_sign_up_path_for(resource) # super(resource) # end end
but code isn't working , getting when feeling form:
here's form code:
<% provide(:title, 'sign free messpay account') %> <div class="row"> <div class="col-xs-5 col-xs-offset-2" style="margin-top: 10%"> <%= image_tag("signup.jpg", alt: "thapar",width:"475",height: "331",class:"img-responsive") %> </div > <div class="col-xs-5" id="signup_form" style="margin-top: 10%"> <%= image_tag("messpay.gif", alt: "messpay",height: "38",width: "120") %> <p style="font-size:30px;font-weight:100;"> create account </p> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) |f| %> <%= devise_error_messages! %> <p style="font-size: 0.87em">messpay account <%= link_to "what's this?","#" %></p> <%= f.text_field :roll_number, class:'form-control',placeholder:"roll number" %> <%= f.email_field :email, class:'form-control',placeholder:"email" %> <%= f.password_field :password, class:'form-control',placeholder:"password"%> <%= f.password_field :password_confirmation, class: 'form-control',placeholder:"password confirmation"%> <%= f.submit "create account", class: "btn btn-primary" %> <% end %> <p style="margin-top: 10%;color: gray;">already have messpay account<span onclick="opennav()"style="color:#0c90db;cursor:pointer;"> login here !!</span></p> </div> </div>
am using params ? can't understand eaxctly why happening !
i think should put below code in appliction_controller.rb
before_action(:configure_permitted_parameters, if: :devise_controller?) def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_up) << [:roll_number,:resident_id]] devise_parameter_sanitizer.for(:account_update) << [:roll_number,:resident_id]] end
hope you
Comments
Post a Comment