Rails/Devise/Bootstrap: Can't access @minimum_password_length in sign up modal -
i've created bootstrap modal devise sign up, accessible via link on landing page navbar. modal working properly, i.e. creating user. when try add password length hint password input - nothing. checked value of devise instance variable @minimum_password_length , nil. suggestions?
rails 4.2.6, ruby 2.3.0, bootstrap 4.0.0.alpha3, devise 4.0.0, simple form 3.2.1
/config/initializers/devise.rb
... if rails.env.test? || rails.env.development? config.password_length = 2..128 else config.password_length = 8..128 end ...
/db/migrate/20160417123456_devise_create_users.rb
... ## confirmable t.string :confirmation_token t.datetime :confirmed_at t.datetime :confirmation_sent_at t.string :unconfirmed_email # if using reconfirmable ... add_index :users, :confirmation_token, unique: true ...
/app/models/user.rb
... devise :confirmable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable ...
/views/shared/_navbar.html.haml
... %li.nav-item.pull-xs-right = link_to 'sign up', '#signupmodal', data: { toggle: 'modal', target: '#signupmodal' }, id: 'sign-up-nav-link', class: 'account-nav-link nav-link' %li.nav-item.pull-xs-right = link_to 'log in', '#loginmodal', data: { toggle: 'modal', target: '#loginmodal' }, id: 'log-in-nav-link', class: 'account-nav-link nav-link'
/app/views/shared/_sign_up_modal.html.haml
#signupmodal.modal.fade{ tabindex: '-1', role: 'dialog', aria: { labelledby: 'signupmodallabel', hidden: 'true' } } .modal-dialog{ role: 'document' } .modal-content .modal-header %button.close{ type: 'button', data: { dismiss: 'modal' }, aria: { label: 'close' } } %span{ aria: { hidden: 'true' } } %i.fa.fa-times-circle %h4#signupmodallabel.modal-title sign = simple_form_for resource, as: resource_name, url: registration_path(resource_name) |f| .modal-body = f.error_notification %fieldset.form-group = f.input :email, label: 'email address', required: 'true', autocomplete: 'off', input_html: { id: 'email-input', class: 'form-control' } %fieldset.form-group = f.input :password, label: 'password', required: 'true', autocomplete: 'off', input_html: { class: 'form-control' }, hint: ('min. length of #{ @minimum_password_length }' if @validatable) %fieldset.form-group = f.input :password_confirmation, label: 'password confirmation', required: 'true', autocomplete: 'off', input_html: { class: 'form-control' } %fieldset.form-group = f.input :subdomain, label: 'subdomain', required: 'true', autocomplete: 'off', input_html: { class: 'form-control' } - if devise_mapping.rememberable? = f.input :remember_me, label: 'remember me', as: :boolean, boolean_style: :inline .modal-footer .actions = link_to 'cancel', 'javascript:;', data: { dismiss: 'modal' }, class: 'btn btn-sm btn-secondary' = f.button :submit, 'sign up', disable_with: 'creating account...', class: 'btn btn-sm btn-primary'
/app/helpers/application_helper.rb
def resource_name :user end def resource @resource ||= user.new end def devise_mapping @devise_mapping ||= devise.mappings[:user] end
/config/routes.rb
root to: 'landing_page#index' devise_for :users ...
i solved problem, handing @minimum_password_length view in views controller function. can access minimum_password_length using devise model. in case it's user model. in code:
@minimum_password_length = user.password_length.min
Comments
Post a Comment