Here you go:
def after_update_save(record)
#
------------------------------------------------------------------------------------
# This is JUST a band-aid. It's here because there is an issue
with has_one :through
# either in ActiveScaffold or in Rails itself. Once that
issue is fixed, this may
# be able to be removed
#
main_store_post = params[:record][:main_store].to_i || 0
if !main_store_post.nil? && main_store_post > 0
# Create a new SyncConfig Store Record
scs = SyncConfigurationStore.new
scs.StoreId = main_store_post
scs.SyncConfigurationId = record.Id
if scs.save # (and try to save it)
# Save the associated store as a Main Store
store = Store.find main_store_post
store.MainStore = 1
if !store.save
# Roll back!
scs.delete
record.errors.add(:base, 'The Main Store could
not be set.')
else
# Find any orphaned Main Stores
# ... We'll use a named_scope in order to save
query power
Store.named_scope :parent_store,
:conditions => 'Store.MainStore = 1 AND
Store.Id NOT IN (SELECT DISTINCT(StoreId) FROM SyncConfigurationStores
WHERE StoreId IS NOT NULL)'
s = Store.parent_store # Going to get an array
here...
# Make sure any exsting old Main Store(s)
is(are) demoted...
if s.respond_to?(:each)
s.each { |s_|
s_.MainStore = 0
s_.save
}
# Also clear out any unused
SyncConfigurationStores
scs = SyncConfigurationStore.all
:conditions => 'StoreId IS NULL'
scs.each { |scs_|
scs_.delete if scs_.respond_to?(:delete)
}
end
end
else
record.errors.add(:base, 'The Main Store could not
be saved.')
end
end
#
#
------------------------------------------------------------------------------------
end
On 09/22/2010 07:23 AM, Sergio Cambra .:: entreCables S.L. ::. wrote:
On Miércoles, 22 de Septiembre de 2010 15:04:28 Michael Bahnmiller escribió:
Sergio,
I'm using after_update_save(record) because there is actually some stuff
that I need to do there. In that method I do some saving of data that
is not performed by AS. When I'm done there, and the form is closed,
the record on the grid is not updated. I don't have another custom
action. So... if I try to use this code in the after_update_save
function, I get an error saying that I'm can't call more than one redirect.
Any thoughts? (I do have to do this from the after_update_save(record)
method.)
Ok, I misunderstand you when you said custom action code. Post your
after_update_save method, probably your code won't set fields in the record and
could be changed to do it.
Thanks,
M
On 09/22/2010 01:34 AM, Sergio Cambra .:: entreCables S.L. ::. wrote:
On Miércoles, 22 de Septiembre de 2010 08:57:04 Michael Bahnmiller
escribió:
I'm doing this in the after_update_save(record) method.
What will I put in that method to get it to refresh the grid? (I tried
the record.groups(true) suggestion, but groups is not a method on
record).
Thanks, Sergio, et al!
Your problem is different than Andrey's one, I answered to you, I'm
copying the answer again, but you don't have to use after_update_save
because you don't need to refresh the record, you have to send a response
which update the row.
Andrey had to reload groups association because row was updated with
invalid data for that association.
If your custom action update a row, you can use:
respond_to do |format|
format.html { return_to_main }
format.js { render 'update_row' }
end
Mikelb
On 09/21/2010 03:18 AM, Sergio Cambra .:: entreCables S.L. ::. wrote:
On Martes, 21 de Septiembre de 2010 11:13:36 Andrey Voronkov escribió:
yes, I have subform for Jet and Group represents as select list (I
want RecordSelect in future) in this subform
ActiveRecord is caching previous association value, when it was empty,
although is strange. You can add after_create_save to reload that
association: def after_create_save(record)
record.groups(true)
end
2010/9/21 Sergio Cambra .:: entreCables S.L.
::.<[email protected]>:
On Martes, 21 de Septiembre de 2010 10:41:47 Andrey Voronkov escribió:
Oops! that is not virtual column - sorry.
It has_many :through association now.
ChargeCard ---< Jet>--- Group
I need to display groups in list action in AS for ChargeCard model.
So all other columns shows on create in a new row, and groups are
"-". Only after refreshing the list I see groups.
Are you filling that association in the form?
2010/9/21 Sergio Cambra .:: entreCables S.L. ::.
<[email protected]>:
On Martes, 21 de Septiembre de 2010 03:17:55 Andrey Voronkov
escribió:
+1
my virtual column value does not appear in new row on create (all
"natural" fields are present). Only reloading or closing and
reopening ajax box (i'm talking about nested list) does the trick.
Your problem has nothing to see with mike issue. Post your virtual
column definition
2010/9/21 mikelb<[email protected]>:
Is there a way to refresh the Grid on update? I'm performing an
action using custom code, and the value isn't being put back into
the grid row until the page is refreshed.
Thanks for the help,
M
--
You received this message because you are subscribed to the
Google Groups "ActiveScaffold : Ruby on Rails plugin" group. To
post to this group, send email to
[email protected]. To unsubscribe from this group,
send email to
[email protected]. For more options,
visit this group at
http://groups.google.com/group/activescaffold?hl=en.
--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--
You received this message because you are subscribed to the Google
Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to
this group, send email to [email protected]. To
unsubscribe from this group, send email to
[email protected]. For more options,
visit this group at
http://groups.google.com/group/activescaffold?hl=en.
--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--
You received this message because you are subscribed to the Google
Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to this
group, send email to [email protected]. To unsubscribe
from this group, send email to
[email protected]. For more options, visit
this group at
http://groups.google.com/group/activescaffold?hl=en.
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.