i'm kinda new coding on rails. great if me out think might noob question.here's code:
def create @project = project.new(params[:project]) if @project.save redirect_to new_project_path end student=@project.student_str.split(";") @users = user.where(:code => student) @users.each |c| puts c.email end @users.each |c| puts "i'm here" c.projects = "#{c.projects};#{@project.id}" end end so, in create method, each time new project created string called student_str stored id number of each student seperated ";". split string array using split function array of student id's. have puts c.email , puts "i'm here" make sure loops working fine. proper outputs on terminal.
the problem here
c.projects = "#{c.projects};#{@project.id}" that not seem working. model not updated when line executed. no errors though. can tell me might have fix this?
thanks!
you have call c.save after updated projects attribute. otherwise object updated not database next time load changes gone.
Comments
Post a Comment