У меня возникла новая проблема, попытка реализовать устройство с коконом и его не сохранить в БД. ПОЖАЛУЙСТА ПОМОГИТЕ !!! : Dкокон с разработкой не работает Вложенная форма
Модель пользователя:
class User < ActiveRecord::Base
has_many :telefonos
accepts_nested_attributes_for :telefonos, :reject_if => :all_blank, :allow_destroy => true
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
Telefono модель:
class Telefono < ActiveRecord::Base
belongs_to :user
end
В мой контроллер пользователей:
def secure_params
params.require(:user).permit(:telefonos_attributes: [:id, :telefono, :_destroy])
end
Мой AplicactionController
Class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:nombre, :email, :password) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:email, :password, :current_password, :region_id, :ciudad_id, :nombre, telefonos_attributes: [:telefono, :user_id]) }
end
end
мой взгляд редактирования:
<h3>Edit <%= resource_name.to_s.humanize %></h3>
<%= simple_form_for resource, :as => resource_name, url: registration_path(resource_name), :html => { :method => :put} do |f| %>
<div class="form-group">
<%= f.input :nombre, :autofocus => true, class: 'form-control' %>
<%= f.association :region, :include_blank => false %>
<%= f.association :ciudad, :include_blank => false %>
</div>
<h1>Telefono</h1>
<div id="telefonos">
<%= f.simple_fields_for :telefonos do |t| %>
<%= render 'telefono_fields', :f => telefono %>
<% end %>
<div class="links">
<%= link_to_add_association 'add telefono', f, :telefonos %>
</div>
</div>
<%= f.submit 'Update' %>
<% end %>
мой _telefono_fields.html.erb
<div class="nested-fields">
<%= f.input :telefono %>
<%= link_to_remove_association "remove telefono", f %>
С уважением,
В 'telefonos_attributes' вы должны иметь еще два атрибута' id' и '_destroy'. Это только для вашей информации. Это может быть причиной этой проблемы или нет. Просто попробуй. И вы получаете какие-либо ошибки в консоли, вы проверили? – Deep
Спасибо, но не создайте ошибку в консоли !! :/У вас есть учебник? –
Неопроверенные параметры: nombre, region_id, ciudad_id, telefonos_attributes –