0

I added a few more fields to a devise model, and was trying to create form fields for them in the template. My template looks like this here.

So what I tried is add a street_number field to the devise model and do

<div class="form-group">
      <%= f.label :street_number %>
      <%= f.street_number_field :street_number, class: "form-control", required: true %>
</div>

Then, I get a error message like

undefined method `street_number_field'

Is there anything I need to do to make sure street_number is recognized, and I can use the method 'street_number_field' like the default devise fields?

1
  • The error you get is solved with the answer provided by @Padmanaban Gokula. Also in order to be able to update your migrated fields you will need to configure the permitted parameters in application controller. Commented Dec 7, 2015 at 23:38

2 Answers 2

1

there is no street_number_field in form helpers. Use number_field instead. Check this link for various field types http://guides.rubyonrails.org/form_helpers.html

 <div class="form-group">
          <%= f.label :street_number %>
          <%= f.number_field :street_number, class: "form-control", required: true %>
    </div>
Sign up to request clarification or add additional context in comments.

Comments

0

You need to add this lines into your aplicaction_controller.rb file: (replace the fields you need)

class ApplicationController < ActionController::Base

  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:street_number, :email, :password, :password_confirmation, :remember_me, :avatar) }
    devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :email, :password, :remember_me) }
    devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:street_number, :email, :password, :password_confirmation, :current_password) }
  end

end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.