Ruby on Rails Sunday, November 27, 2011


hey, 

is there any help, my code of challenge and task model and controller and mongoid.yaml is below

class Challenge
  include Mongoid::Document
  include Mongoid::Timestamps::Created
  include Mongoid::Timestamps::Updated
 
  # TASKS
  embeds_many :tasks                        
  accepts_nested_attributes_for :tasks
   
  field :title, :type=>String
  field :description, :type=>String
   
 end


class Task
  include Mongoid::Document
 
  # name of task
  field :name, :type => Hash
  # score translates to Point on UI 
  field :score_by
  # score translates to Point on UI
  field :score
  # task status
  field :is_complete, :type => Integer, :default => 0
 
  embedded_in :challenge
end               


def update
 
    @challenge = Challenge.find(params[:id])
    #raise ch = params[:challenge].inspect
    if @challenge.update_attributes(params[:challenge])
      redirect_to :action => 'index', :id => @challenge
    else
      render :action => edit
    end
  end


mongoid.yaml

defaults: &defaults
  allow_dynamic_fields: true
  parameterize_keys: true
  persist_in_safe_mode: true
  raise_not_found_error: true
  reconnect_time: 3
  use_object_ids: false 

development:
  
  host: localhost
  database: xxxxx_development

test:
  host: localhost
  database: xxxxx_test

# set these environment variables on your prod server
production:
  host: localhost
  port: 27017
  database: xxxxx_development
  #host: <%= ENV['MONGOID_HOST'] %>
  #port: <%= ENV['MONGOID_PORT'] %>
  #username: <%= ENV['MONGOID_USERNAME'] %>
  #password: <%= ENV['MONGOID_PASSWORD'] %>
  #database: <%= ENV['MONGOID_DATABASE'] %>
  # slaves:
  #   - host: slave1.local
  #     port: 27018
  #   - host: slave2.local
  #     port: 27019



---------- Forwarded message ----------
From: Pravin Mishra <diatm.pravin.it.07.27@gmail.com>
Date: 26 November 2011 18:02
Subject: mongoid update_attributes issues
To: rubyonrails-talk@googlegroups.com


hi,

i have two model CHALLENGE and TASK, CHALLENGE embeds_many :tasks and TASK embbeded_in :challenge
when i updating particular task attrubutes then it working
@ch_ts_update.tasks.where(:name => params[:name]).update(:is_complete => 1)

when trying to update whole task using challenge params
@challenge.update_attributes(params[:challenge])

instead of updating existing tasks it creating new tasks. I think, i m missing some configuration in mangoid.yml

thanks in advance!!!!!!!
Pravin Mishra


--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment