Unpermitte do not save me the parameters ruby on rails 5.1.1

0

hello is that they are not keeping me the parameters charge, management and locality and I do not know why who helps me thanks

Unpermitted parameters:: position,: management,: locality

schema.rb

create_table "users", force: :cascade do |t|
  t.string "name"
  t.string "cargo"
  t.string "gerencia"
  t.string "localidad"
  t.string "nombreemail"
  t.string "telefono"
  t.string "extension"
  t.datetime "created_at", null: false
  t.datetime "updated_at", null: false
  t.string "email", default: "", null: false
  t.string "encrypted_password", default: "", null: false
  t.string "reset_password_token"
  t.datetime "reset_password_sent_at"
  t.datetime "remember_created_at"
  t.integer "sign_in_count", default: 0, null: false
  t.datetime "current_sign_in_at"
  t.datetime "last_sign_in_at"
  t.string "current_sign_in_ip"
  t.string "last_sign_in_ip"
  t.index ["email"], name: "index_users_on_email", unique: true
  t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

model   user.rb

  class User < ApplicationRecord  

      devise :database_authenticatable, :registerable,
        :recoverable, :rememberable, :trackable, :validatable
      has_many :assignments
      has_many :roles, :through => :assignments
  end

users_controller.rb

class UsersController < ApplicationController

 before_action :set_user, only: [:show, :edit, :update, :destroy] 

# GET /users/new
def new
  @user = User.new
end

def create
  @user = User.new(user_params)
  respond_to do |format|
    if @user.save
      format.html { redirect_to @user, notice: 'User was successfully created.' }
      format.json { render :show, status: :created, location: @user }
    else
      format.html { render :new }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end


private

def set_user
  @user = User.find(params[:id])
end

def user_params
  params.require(:user).permit(:name, :cargo, :gerencia, :localidad , :nombreemail,
  :telefono, :extension, :password,:email)
end 

end

new.html.erb registrations / new.html.erb

<%= bootstrap_devise_error_messages! %>


   <div class="row">
     <div class="col-md-4 col-sm-4"></div>
     <div class="col-md-4 col-sm-4 col-xs-12">
     <div class="panel panel-default devise-bs">
     <div class="panel-heading">
      <h4><%= t('.sign_up', default: 'Registrarme') %></h4>
     </div>
     <div class="panel-body">

      <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { role: 'form' }) do |f| %>
      <div class="form-group">
        <%= f.label :nombre %>
        <%= f.text_field :name ,label: "Nombre completo",
  placeholder: "Ingrese el nombre completo",input_html: { title: 'Nombre del usuario' }, autofocus: true, class: 'form-control'%> 
    </div>

    <div class="form-group">
      <%= f.label :Cargo %>
      <%= f.text_field :cargo ,
  placeholder: "Ingrese el nombre del cargo ",input_html: { title: 'Cargo del usuario' }, autofocus: true, class: 'form-control'%>  
    </div>
    <div class="form-group">
      <%= f.label :Gerencia%>
      <%= f.text_field :gerencia  ,
  placeholder: "Ingrese el nombre de la gerencia ",input_html: { title: 'Gerencia del usuario' }, class: 'form-control'%>  
   </div>
   <div class="form-group">
     <%= f.label :localidad %>
     <%= f.text_field :localidad ,
  placeholder: "Ingrese la planta donde elabora",input_html: { title: 'Localidad del usuario' }, autofocus: true, class: 'form-control'%>  
   </div>

   <div class="form-group">
      <%= f.label :email %>
      <%= f.email_field :email, autofocus: true, class: 'form-control' %>
  </div>
  <div class="form-group">
    <%= f.label :password %>
    <%= f.password_field :password, class: 'form-control' %>
  </div>
  <div class="form-group">
    <%= f.label :password_confirmation %>
    <%= f.password_field :password_confirmation, class: 'form-control' %>
  </div>
   <center>
    <%= f.submit t('.sign_up', default: 'Sign up'), class: 'btn btn-primary' %>
   </center> 
<% end %>

                   

 

Gemfile

gem "select2-rails"
gem 'devise', '~> 4.2'
gem 'devise-bootstrap-views'
gem 'devise-i18n'
gem 'cancancan', '~> 1.15'
gem 'mail'
    
asked by juan gomez 23.10.2017 в 06:35
source

1 answer

0

Devise uses its own controller to create the users; if you look at the log , you will see that the contolador is Devise::RegistrationsController , so your controller UsersController is not necessary (at least not to create users).

To Devise accept the parameters cargo , gerencia and localidad , you must configure them in the contolador ApplicationController :

class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:cargo, :gerencia, :localidad])
  end
end
    
answered by 23.10.2017 / 14:14
source