неразрешенный параметр в имеет и принадлежит многим ассоциациям

Я пытаюсь создать приложение rails 4 с пользовательской моделью и отраслевой моделью. У них есть ассоциация has_and_belongs_to_many между ними обоими. Я создал таблицу соединений в соответствии с руководствами http://guides.rubyonrails.org/association_basics.html Я получаю недопустимый параметр для :industry_ids. Поэтому я следовал разделу разработки по надежным параметрам.

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

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) << :about
    devise_parameter_sanitizer.for(:sign_up) << :industry_ids
  end
end

Но, как я прочитал здесь http://blog.sensible.io/2013/08/17/strong-parameters-by-example.html, для такой ассоциации мне нужно сообщить рельсам, что это массив.

Как исправить создание пользователей с ассоциацией :industries?


person Harry Moreno    schedule 24.09.2013    source источник


Ответы (1)


В итоге я использовал блок.

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

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u|
      u.permit(:email, :password, :password_confirmation,
               :about, industry_ids: []) }
  end
end
person Harry Moreno    schedule 24.09.2013