Displaying 20 results from an estimated 10000 matches similar to: "When saving parent fails, children will still be updated"
2007 May 21
7
How do I stop a column being updated by model.save?
One of my models has a column that is updated very frequently from a
separate process, so it is important that when a record is saved in
rails, this column should be left alone. In the update method of the
controller I have:
@record = MyModel.find(params[:id])
@record.update_attributes(params[:my_model])
params[:my_model] doesn''t have a reference to the column I''m talking
2006 Jan 03
5
update command not updating DB
I really need your help guys... I spent 6 hours on this simple update
command today that should work. It works fine in my other controller,
but doesn''t work in this one for some reason.
Here is my controller code for the list view, and then the update
command:
======
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if
2006 Feb 23
3
has_many: inserting children when inserting parent
disclaimer: am in the midst of my first ruby/rails project
I have a situation where I want several child records to be created when
a new parent record is created. The following represents my first stab
at coding it, am I on the right track?
Here is the model:
parents
----------
id
name
children
----------
id
parent_id
name
class Parent < ActiveRecord::Base
has_many: children
end
2005 Nov 30
8
nested attributes with update_attributes()
Hi,
I am trying to use the update_attributes on object with nested
attributes and I am getting the following error:
ProductPrice expected, got HashWithIndifferentAccess
Here''s the situation (simplified):
class Product < ActiveRecord::Base
belongs_to :productPrice
end
class ProductPrice < ActiveRecord::Base
has_one :product,
:dependent => true
2006 Mar 02
6
Newb question about facade columns
Hello,
I am trying to deal with a database table that contains a date in the
form of the number of seconds since epoch. Data is inserted in this
format by an existing script that I can''t change, so a schema change
isn''t realistic.
I would like to allow humans to view and edit this data in the form of
an actual human-readable date. I figured a facade column would be the
2006 Jun 15
8
rails saves it to the database and I don''t want to
Hello:
I am developing a web application to book machines for an event.
so I have an event model
class Event < ActiveRecord::Base
has_many :datetimes
...
end
and a datetime model
class Datetime < ActiveRecord::Base
belongs_to :event
...
end
I have developed a view with the event information and information for
the datetimes. and in the event_controller when I capture a datetime I
2006 Jan 15
2
single table inheritance: change object ''type'' after create?
Hey folks,
I''m trying to keep track of couple of different kinds of "entities" in
my rails app: "people", "organizations", and "committees". I have a
single Entities table in the database, and I''m using Single Table
Inheritance to keep the different subclasses in the same table, with a
field "type".
My problem comes when
2008 Aug 26
1
transaction not working with update_attributes!
I am trying to wrap the updating of two models in a transaction and
when the transaction fails it is not rolling back.
My method is :
def update_attributes(user,params)
@user = user
@company = user.company
begin
User.transaction do
@user.update_attributes!(params[:user])
@company.update_attributes!(params[:company])
end
true
rescue
false
2005 Dec 19
2
update_attrbutes without saving?
Hello all,
Is there a method for updating all the attributes from a hash without
saving to the database? (the counterpart of update_attributes but
without saving).
What I want to do is:
person = Person.find(params[:id])
person.update_without_saving(params[:person]) #update the in-memory
object.
# Process person object
.......
person.save
I know that when you are creating a new object, you can
2006 Jan 14
14
Javascript/AJAX Debugging
Hello !
I''m trying to implement something similar to the "multiple updates" section
of the Web2.0 chapter of the Agile book.
I implemented my version, and nothing is happening. No javascript errors,
my logs look fine, page is rendered fine... just no Effect.Highlight. Here
is the code:
views/causes/cause_home/index.rhtml
===============
<%= form_remote_tag(:complete =>
2006 Mar 04
13
file_column
Restricting size of an uploaded file, is how is that possible? If I
do not want a user to upload a file larger than X bytes, can it
easily be done?
If I also would like restrict the types of files that can be
uploaded, how may I do so?
Thank you,
Sharkie
2009 May 24
6
belongs_to not saving foreign key
Under Rails 2.3.2 using a completely brand new project, I have 2
models:
class Author < ActiveRecord::Base
# name:string
end
class Book < ActiveRecord::Base
# title:string
belongs_to :author # author_id
end
And a simple test where i create a Book with an Author using the
belongs_to and then update the foreign key directly:
require ''test_helper''
class BookTest
2006 Jul 11
3
update_attributes and save!
I notice that ActiveRecord::Base.update_attributes() calls save().
What if I want to get an exception if the save fails? Is there a way to
get the update_attributes() function plus the save! function?
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
2006 Apr 15
0
parent.children not updated (has_many)
Hi guys!
class Parent < ActiveRecord::Base
has_many :children
end
class Child < ActiveRecord::Base
belongs_to :parent
end
I do:
parent = Parent.find(1, :include => :children)
parent.children.find(3).update_attribute(''name'', ''Tom'') (or
parent.children.find(3).name = ''Tom'')
parent.children.find(3).name
=> ''old
2006 Mar 10
4
problem when looping through habtm children in a view
I have this code in a view:
<% for topic in @topics %>
<%= topic.id %> <%= topic.dr_title %><br/>
<ul>
<% for doc in topic.child_documents %>
<%= doc.dr_title %><br/>
<% doc = nil %>
<% end %>
</ul>
<% end %>
Though the topic titles and IDs display correctly,
2006 Apr 20
3
Need help cutting down on db traffic
I''m having performance issues with one of my actions, and think I''ve
narrowed it down to too many sql queries.
I have a form with ~60 lines, which takes ~6 sec to save, 60%+ of that
is db io. There''s 650+ lines of log data, most of which are
AR/queries.
The app is a simple dual entry book keeping thingy, and the form in
question contains a journal entry along with a
2006 Apr 28
1
@model.update_attributes(params[:model]) without saving?
Is it possible to update the parameters from a form without saving?
@model.update_attributes(params[:model]) will save the model after
updating its attributes. I''d just like the attributes updating without
a save.
Thanks
Chris
--
Posted via http://www.ruby-forum.com/.
2006 Jun 21
5
model with not te be updated attributes ?
Hi List,
I have a table that contains several fields that must be initialized
when first created, but may not be altered afterwards (when updating the
other fields) because they can be changed by external processes.
I noticed that the ActiveRecord update commands (even update_attribute)
only seem to work by loading the complete record, changing fields that
need to be changed and doing a full
2009 Feb 19
3
Associated child records not created on creation of a parent.
I am trying to create a record with association. Within the create
method, I would also like to pre-populate dependent (has_many) records
from a template in the database.
The child records are <u>mysteriously rolled back </u> if I insert
them in a loop. If I try to insert a single child record, it works.I
have read the books and tried to google my way out of this but am at a
dead
2006 Oct 16
3
Saving many_to_many
Ahoy, i''m trying to save a many to many between "talent" and "vital
stat"
talent_controller.rb
def edit
@talent = Talent.find(params[:id], :include => [:talent_type,
:vital_stats])
@talent_types = TalentType.find_all
@vital_stats = VitalStat.find_all
if request.post?
@talent.attributes = params[:talent]
@talent.attributes =