I am using mysql + webrick
Saving an instance of a model class inserts null values or zeros
instead of the actual values
Code below has some lines commented since I noticed a thread
where one individual encountered a similar situation but no
confirmed solution was identified.
Thanks in advance.
def save_refer_friends
begin
@email = params[:email1]
@id = session[:user].id
# @refer_friends = ReferFriends.new(@email, Time.now, @id)
@refer_friends = ReferFriends.new()
@refer_friends.email = @email
@refer_friends.ref_user_id = session[:user].id
@refer_friends.event_time = Time.now
@refer_friends.save
redirect_to ''/''
rescue Exception => e
logger.error e
redirect_to ''/''
end
end
class ReferFriends < ActiveRecord::Base
#validates_presence_of :email, :event_time, :ref_user_id
#attr_writer :ref_user_id, :event_time, :email
#attr_reader :email, :ref_user_id, :event_time
def email
@email
end
def event_time
@event_time
end
def ref_user_id
@ref_user_id
end
def email=(email)
@email = email
end
def event_time=(event_time)
@event_time = event_time
end
def ref_user_id=(ref_user_id)
@ref_user_id = ref_user_id
end
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
Sanjeev Bb wrote:> I am using mysql + webrick > > Saving an instance of a model class inserts null values or zeros > instead of the actual values > Code below has some lines commented since I noticed a thread > where one individual encountered a similar situation but no > confirmed solution was identified. > > Thanks in advance. >Eliminating my access methods in the model solved the problem. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Sanjeev Bb wrote:> Sanjeev Bb wrote:>> Saving an instance of a model class inserts null values or zeros >> instead of the actual values >> Code below has some lines commented since I noticed a thread >> where one individual encountered a similar situation but no >> confirmed solution was identified. > > Eliminating my access methods in the model solved the problem. >Hi Sanjeev ActiveRecord uses a hash, @attributes, to hold attribute values, and provides ''magic'' accessors to those values (using method_missing) if you haven''t provided your own accessors. If you wish to write your own accessors, use read_attribute and write_attribute to access the attribute values in the hash. See http://railsmanual.com/class/ActiveRecord%3A%3ABase#read_attribute regards Justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---