Thursday, 15 August 2013

ruby on rails - PG Error - Data Mismatch -



ruby on rails - PG Error - Data Mismatch -

failures: 1) post /v1/notes/id saves lat, lon, note text, note photo, recipients, , expiration failure/error: post '/v1/notes', { activerecord::statementinvalid: pg::datatypemismatch: error: argument of must type boolean, not type integer line 1: select "users".* "users" (45) limit 1 ^ : select "users".* "users" (45) limit 1

i'm assuming next method should find or create user object, reason i'm getting above error.

def create @note = note.new(note_params) if @note.save render end end private def note_params { #user_id: params[:user_id], user_id: user[:id], lat: params[:lat], lon: params[:lon], note_text: params[:note_text], photo_uri: params[:photo_uri], expiration: params[:expiration] } end def user user = user.find_or_create_by(params[:user_id]) end

i'm assuming you'd want utilize user method create or find user object based on user_id go note_params, not clear on difference between using user_id: user[:id] instead of #user_id: params[:user_id].

the problem in user method. need provide hash attributes needed finding or creating userin database.

def user user = user.find_or_create_by(id: params[:user_id]) end

with params[:user_id] getting id of user right params hash. user[:id] calling user method returns user object, retrieves id (you phone call user.id)

ruby-on-rails postgresql type-mismatch

No comments:

Post a Comment