I want to override an attribute in my Rails Project but the problem is, that in my form (Formtastic) it still displays the database value and not the one from the getter. Do I have to write a custom getter and setter with annother name and save the value to the first attribute or is there a better way to do this?
Asked
Active
Viewed 21 times
1 Answers
0
If I understand you correctly you want to have a field in your form with a specific value, that is different from the actual value in the database. In this case you could pass the value option like this:
f.input :field, :input_html => { :value => "value" }

IngoAlbers
- 5,722
- 6
- 31
- 45
-
Ok, this definately works, thanks :) To explain my problem again in more detail: I want to save an IP-Adress to the database and chose the type to be bigint. Now I have to parse the String-IP before I write it to the database and before I read it. I did that by overriding the getter and setter for my IP attribute. But the problem was, that formatastic doesn't get the getter value, but the database value directly (the bigint). I hope you can follow my problem now :D Is the value solution the best? – Raighar Aug 31 '15 at 13:14