Devise and Ruby on Rails: On Sign Up Alle valideringer mislykkes med “Can't be Blank”

stemmer
1

Jeg prøver å registrere meg Affiliate bruker Devise.

/affiliates/registrations_controller.rb

class Affiliates::RegistrationsController < 
    Devise::RegistrationsController
    include StatesHelper, ApplicationHelper

    before_action :configure_sign_up_params, only: [:create]
    before_action :configure_account_update_params, only: [:update]

    # GET /resource/sign_up
    def new
        @plan = AffiliatePlan.find_by(nickname: params.permit(:plan)[:plan].downcase)
        super
    end

    # GET /resource/edit
    def edit
        @states = us_states
        super
    end

    # PUT /resource
    def update
        @states = us_states
        super
        if resource.address_coordinates.length > 1 
            resource.services.each{ |s| s.update_attributes( {lonlat: POINT(#{resource.address_coordinates.join(' ')})})}
        end 
    end

    def update_resource(resource, params)
        resource.update_without_password(params)
    end

    protected

    # If you have extra params to permit, append them to the sanitizer.
    def configure_sign_up_params
        devise_parameter_sanitizer.permit(:sign_up, keys: [:business_name, :website, :phone, :affiliate_plan_id, contact_name: [:first_name, :last_name], address: [:street_address, :address_line2, :city, :state, :zip_code]])
    end

    # If you have extra params to permit, append them to the sanitizer.
    def configure_account_update_params
        devise_parameter_sanitizer.permit(:account_update, keys: [:business_name, :website, :phone, :affiliate_plan_id, contact_name: [:first_name, :last_name], address: [:street_address, :address_line2, :city, :state, :zip_code]])
    end

    # The path used after sign up.
    def after_sign_up_path_for(resource)
        affiliate_signups_path
    end
end

/affiliates/registrations/new.html.erb

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>

    <%= devise_error_messages! %>

    <% if @plan %>
        <%= f.hidden_field :affiliate_plan_id, value: @plan.id %>
    <% else %>
        <%= f.hidden_field :affiliate_plan_id, value: resource.affiliate_plan_id %>
    <% end %>

    <%= f.fields_for :contact_name do |n| %>

        <%= n.text_field :first_name, autofocus: true, placeholder: First Name*, class: form-control, required: true %>

        <%= n.text_field :last_name, placeholder: Last Name*, class: form-control, required: true  %>
     <% end %>

    <%= f.text_field :business_name, placeholder: Company Name, class: form-control %>

    <%= f.email_field :email, autocomplete: email, placeholder: Email Address*, class: form-control, required: true %>

    <%= f.password_field :password, autocomplete: new-password, placeholder: Create a Password, class: form-control, required: true %>

    <%= f.password_field :password_confirmation, autocomplete: new-password, placeholder: Confirm Password, class: form-control, required: true %>


    <%= f.submit Next, class: btn btn-primary btn-sm %>
<% end %>

routes.rb

devise_for :affiliates, path: partners, controllers: {
  sessions: 'affiliates/sessions',
  registrations: 'affiliates/registrations'
}

Når jeg sender skjemaet får jeg alltid valideringsfeil:

7 errors must be fixed
   - Email can't be blank
   - Password can't be blank
   - Password is too short (minimum is 9 characters)
   - Password must contain at least one digit
   - Password must contain at least one punctuation mark or symbol
   - Password must contain at least one upper-case letter
   - Affiliate plan must exist

Loggen viser en umiddelbar tilbakestilling, men ingen annen informasjon:

Started POST /partners for 127.0.0.1 at 2020-05-25 14:09:59 -0400
Processing by Affiliates::RegistrationsController#create as HTML
  Parameters: {utf8=>✓, authenticity_token=>SowYVWzTqVYdwZWjYjNc3hlGC5UITqt+bKjQuSATOpLcdVGb52x7gEi8p15MmhlZrLNLpD07fCxp5Gya8/cQMg==, affiliate=>{affiliate_plan_id=>2, contact_name=>{first_name=>Stephen, last_name=>Tilly}, business_name=>1995, email=>sarwerera@email.com, password=>[FILTERED], password_confirmation=>[FILTERED]}, commit=>Next}
(0.2ms)  BEGIN
  ↳ app/controllers/affiliates/registrations_controller.rb:18
   (0.2ms)  ROLLBACK
  ↳ app/controllers/affiliates/registrations_controller.rb:18
  Rendering affiliates/registrations/new.html.erb within layouts/application
  Rendered affiliates/registrations/new.html.erb within layouts/application (2.6ms)

Jeg er ikke helt sikker på hvor jeg skal dra derfra, noen ideer?

Publisert på 25/05/2020 klokken 20:36
kilden bruker
På andre språk...                            


1 svar

stemmer
0

Jeg kan ikke se ut til å kommentere og stille noen spørsmål ennå, så jeg tar noen antagelser. Men her er noen manglende brikker jeg leter etter: The Affiliate modell, og hvis du konfigurerte den som den viktigste enhetsressursen, eller har du en annen, dvs. User .

Jeg antar at du har et annet Devise resource-oppsett, og det er grunnen til at du har opprettet dette oppsettet. Jeg antar at det er det User . I så fall kan en av hovedårsakene være at Devise forventer den modellen som ressurs, og det er derfor den kaster feil om manglende valideringer. Siden Devise :: RegistrationsController forventer a params[:user] som inneholder e-post og passord.

Forslag: Hvis det er tilfelle, vil jeg vurdere å knytte tilknyttet profil til den eksisterende ressursen og fortsette derfra. Dvs Tilknyttet -> tilhører: til -> Bruker. Det ville gjøre livet ditt enklere;)

Hvis antagelsene mine er gale, gi meg beskjed ????

Svarte 08/06/2020 kl. 07:45
kilden bruker

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more