0

I've got a problem with assigning some value to model attribute and save it. I've tried a lot of ways, but none worked.

@rating = Rating.new(rating_params)
@rating.save
@rating.update_attribute(:ip_address, request.remote_ip)

or

@rating = Rating.new(rating_params)
@rating.ip_address = request.remote_ip
@rating.save

Nothing is working for me :-( Everytime I got NULL in my database for column ip_address

ketysek
  • 1,159
  • 1
  • 16
  • 46

1 Answers1

0

Solution to debug in this situation.

@rating = Rating.new(rating_params)
@rating.ip_address = request.remote_ip

#check is't valid to save: true || false
@rating.valid?

# if false, print error messages
p @rating.errors
p @rating.errors.full_messages

#either way you can try save without validation.
@rating.save(:validate => false)

Also, What data type of column ip_address. You can't save integer into string or vice versa.

remote_ip by default string class, if want to save as integer.

Convert String Ip-address to Integer

7urkm3n
  • 6,054
  • 4
  • 29
  • 46