I wonder if my transaction is well written ?
I create the user record first , then the issue record (no validation)
if the user record is valid and saved
if anything happen when saving the issue, I want to rollback the user
record...
def infos_send
@franchise = Franchise.scoped_by_mother_of_all(true).first
@user = ProspectUser.new(params[:user])
User.transaction do
if @user.save
create_info_request_issue #private method
@issue.save
raise ActiveRecord::Rollback
flash[:notice] = I18n.t(:notice_successful)
redirect_back_or_default :action => ''index''
else
render :action => ''infos''
end
end
end
thanks for you help
erwin
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 21 Mar 2009, at 11:15, Kad Kerforn wrote:> > I wonder if my transaction is well written ? > I create the user record first , then the issue record (no validation) > if the user record is valid and saved > if anything happen when saving the issue, I want to rollback the user > record... >It looks a bit odd - you always raise ActiveRecord::Rollback, no matter what happened. In case you did''t know, if an exception is raised inside the tranasaction block then a rollback will happen for you automatically. Fred> def infos_send > @franchise = Franchise.scoped_by_mother_of_all(true).first > @user = ProspectUser.new(params[:user]) > > User.transaction do > if @user.save > create_info_request_issue #private method > @issue.save > raise ActiveRecord::Rollback > flash[:notice] = I18n.t(:notice_successful) > redirect_back_or_default :action => ''index'' > else > render :action => ''infos'' > end > end > > end > > thanks for you help > > erwin > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 21 Mar 2009, at 11:15, Kad Kerforn wrote: > >> >> I wonder if my transaction is well written ? >> I create the user record first , then the issue record (no validation) >> if the user record is valid and saved >> if anything happen when saving the issue, I want to rollback the user >> record... >> > It looks a bit odd - you always raise ActiveRecord::Rollback, no > matter what happened. > In case you did''t know, if an exception is raised inside the > tranasaction block then a rollback will happen for you automatically. > > FredYes sorry.. this line should have been deleted.. is the remaining code OK ? thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---