jeudi 16 février 2017

why my user_id is updated to null ? in Rails

I have 2 model one for user(amitians) other is about.rb to store their details they have a has_one relationship between them but problem is whenever I create a new about my about table has an amitan_id = null

here is my code for models

About_amitians.rb

class AboutAmitian < ApplicationRecord
 belongs_to :amitian
end

Amitian.rb

has_one :about_amitian , foreign_key: "amitian_id"

My AboutAmitian controller

def new
@about_amitian = current_amitian.build_about_amitian
  end

  def create
    @about_amitian = current_amitian.create_about_amitian!(about_amitian_params)
    if @about_amitian.save
            redirect_to :back
            flash[:notice] = 'success'
        else
            render root_url
        end

  end

private

    def about_amitian_params
    params.require(:about_amitian).permit(:dob,:interest,:bio,:catch_phrase,:relationship_status)
    end 

In my server logs I have this query

Update 'about_amitians' set 'amitian_id' = NULL where 'about_amitian'.'id'     = 1

please help. Thankyou

Aucun commentaire:

Enregistrer un commentaire