ruby on rails - Activerecord mass assignment to virtual attribute -
i'm posting following datas:
{"commit"=>"create", "conversation"=>{... , "watchers_ids"=>["2", "3", "4", "5", ...]}}
to following action
def create @conversation = @current_project.conversations.new(params[:conversation]) ... end
and following class
class conversation < rolerecord include watchable end
with module
module watchable def self.included(model) model.attr_accessible :watchers_ids end def watchers_ids=(ids) add_watchers( ids ) end def watchers_ids ... end ... end
however, mass assignment don't work virtual attribute. idea?
there's code that's missing there...
if have has_and_belongs_to_many :watchers
should able assign watcher_ids
without having custom module stuff.
then if can't attribute protected attr_protected
or, more likely, attr_accessible
call in model. can set manually:
@conversation.watcher_ids = params[:conversation][:watcher_ids]
Comments
Post a Comment