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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -