Ruby on Rails
Thursday, April 30, 2015
It's to your credit that you got that working, but it's far from conventional - why not post your attempt to get associations working, with your expected result vs. actual, and you'll soon be greeted with a nice 'AHA!' moment. I bet.
On Thursday, April 30, 2015 at 10:18:28 AM UTC-4, Elizabeth McGurty wrote:
-- On Thursday, April 30, 2015 at 10:18:28 AM UTC-4, Elizabeth McGurty wrote:
I don't know if this is an acceptable practice, but I do the following on update... and it works for me, especially as I have not been been to get table associations to work.
def update
unless params[:id].blank?
unless params[:parent_object].blank?
@p_o_hold = ParentObject.find(params[id])
unless @p_o_hold.blank?
myupdatehash = Hash.new
///// Then I select from params[:parent_object] that I need and apply some validation or database format requirements
myupdatehash = [:field => ...., ]
if @p_o_hold.update_attributes(myupdatehash[0])
@child_object = ChildObject.find(@p_o_hold.id)
unless @child_object.blank?
myupdatehash = [:child_field => @p_o_hold.child_field_value] ## hash object reuse
@child_object.update_attributes(myupdatehash[0])
.....
On Wednesday, April 29, 2015 at 4:42:05 AM UTC-4, Jagmeet Singh wrote:I am inserting a record in 1st table named as Students and I want to insert a record in another table with a value coming from a column Refid which is in Students table
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/717aaec5-c62c-4502-a70e-5109aeb65881%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment