Ruby on Rails
Thursday, September 10, 2015
Hellow.
-- I need to create and update related models i.e. Chat---Chatusers---User.
I have already each-creating in model Chat
def set_members
@chat_users.each do |chat_user|
chatusers.build(user_id: chat_user, num_unread_msgs: 0)
end
end
At first i think this is not a nice solution.
At second i need to update already existing records and if some of them are not represented in input array they must be deleted.
What i looking for may looks like:
(in controller i.e.)
@chat = Chat.find_by(id: params[:id])
@chat.chatusers.update(user_id: params[:chatusers_ids])
# I have list of ids, but it's not to difficult to get list of objects Chatuser
# at first question create need to be instead of update
Thanks.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4e54dd54-f298-4656-87f0-190b2b2b0c27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment