Displaying 2 results from an estimated 2 matches for "find_or_initialize_by_id".
2012 Jan 04
1
AR update / create pattern: is there an easier way?
I find myself writing the following frequently:
r = MyActiveRecord.where(:attr1 => cond1, :attr2 => cond2, ...)
r.exists? ? r.first : r.create
... which has the effect of returning an instance of MyActiveRecord if
all the conditions are met, or creating one if it doesn''t. A variant of
this:
c = MyActiveRecord.new(:attr1 => val1, :attr2 => val2, ...)
r =
2007 Jul 25
5
editing multiple models in one form
Very new to this but would appreciate a hand as this is driving me mad,
I''m trying to update both degree and assigned from a single form, the
degree section updates fine but assigned just retains the same values,
any help much appreciated!
my edit.rhtml file looks like:
<h1>Editing degree</h1>
<%= error_messages_for :degree %>
<%= start_form_tag :action =>