1

attr_accessible親アカウントに基づいてユーザー モデルに追加しようとしています。ユーザー クラス インスタンスがまだその親にアクセスできないことはわかっていますが、これを行う方法がわかりません。どんな提案も素晴らしいでしょう。

これが私がstrong_params仕事をしている方法であり、ユーザーモデルで同様のことをしたい(またはもっと良いことをしたい)。

#appilcation_controller
  ...
  def config_permitted_parameters
   ...
   devise_parameter_sanitizer.for(:account_update) { |u| u.permit(*user_attributes)}
  end

  def user_attributes
    attrs = [:name, :email, :password, :password_confirmation, :current_password, :primary_account, :account_id]
    @account.user_attributes.each do |att|
      attrs << att[0].to_sym
    end
    attrs
  end

これは今働くものです:

#User.rb

%w[no_call_list informal_name].each do |key|
  attr_accessible key
  store_accessor :properties, key
  scope "has_#{key}", lambda { |value| where("properties @> hstore(?, ?)", key, value) }
end

これは私が働きたいものです

#User.rb

#@account.user_attributes.each do |key|
#current_user.account.user_attributes.each do |key|
  attr_accessible key
  store_accessor :properties, key
  scope "has_#{key}", lambda { |value| where("properties @> hstore(?, ?)", key, value) }
end
4

0 に答える 0