1

ユーザーには多くのポジションがあります。これは、ユーザーの認証のために LinkedIn を呼び出す Auth コントローラーの一部です。

positions.each do |position|

    @li_pos_id = position.id
    @title = position.title
    @company = position.company.name
    @industry = position.company.industry
    @start_month = position.start_date.month
    @start_year = position.start_date.year
    @end_month = position.end_date.month
    @end_year = position.end_date.year

    current_user.positions.build(li_pos_id: @li_pos_id, title: @title, company: @company, industry: @industry, 
      start_month: @start_month, start_year: @start_year, end_month: @end_month, end_year: @end_year)
end

なぜ current_user.positions.build(...) が私の開発 (Postgres) データベースでは位置を作成するのに、Heroku (同じく Postgres) では位置を作成しないのかを突き止めようとしています。私の User オブジェクトは、認証時に問題なく作成されています。私のセッションコントローラーから:

def create
      user = User.from_omniauth(env['omniauth.auth'])
      session[:user_id] = user.id
      redirect_to auth_path
    end

私のユーザーモデルから以下を呼び出します:

def self.from_omniauth(auth)
      where(auth.slice('provider', 'uid')).first || create_from_omniauth(auth)
    end

    def self.create_from_omniauth(auth)
      create! do |user|
        user.provider = auth['provider']
        user.uid = auth['uid']
      end
    end

ユーザー モデルには必要な「has_many :positions」が含まれており、位置モデルには「belongs_to :user」があります。とにかく、 current_user.positions.build(...) 行は開発では適切な位置を作成しますが、本番環境では作成しません。

ここで何か助けていただければ幸いです!ありがとうございました。

4

0 に答える 0