Where to put complicated lifecycle logic

15 views
Skip to first unread message

brettnem

unread,
Sep 18, 2012, 4:40:00 PM9/18/12
to hobo...@googlegroups.com
Hello All,

I have a working lifecycle, but the logic for it is getting quite complicated. Part of the lifecycle requires accessing other system's APIs and has browser redirects in them. This logic feels like controller logic. Am I doing something wrong? Is it possible to call controller methods from a lifecycle?

Thanks,
Brett

Bryan Larsen

unread,
Sep 20, 2012, 9:18:38 AM9/20/12
to hobo...@googlegroups.com
It may feel like controller logic, but it isn't an interface to your
program, so it doesn't belong in controller code.

But it doesn't necessarily belong in model code either. My practice
for stuff like this is to put the external access code into an easily
mockable library and put it in /lib or even into a plugin.

cheers,
Bryan
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/9DZac9RPNxgJ.
> To post to this group, send email to hobo...@googlegroups.com.
> To unsubscribe from this group, send email to
> hobousers+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.

Ignacio Huerta

unread,
Sep 20, 2012, 9:28:49 AM9/20/12
to hobo...@googlegroups.com, brettnem
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I agree with Bryan about moving external logic to a class in /lib,
/services or something similar. You can also tune the transitions in
your controller if you wish:

def do_mark_as_read
notice = Notice.find(params[:id])
if notice.ready?
do_transition_action :mark_as_read
else
flash[:error] = "Please do something first"
redirect_to(:action => 'show')
end
end

Regards,
Ignacio

El 18/09/12 22:40, brettnem escribi�:
> -- You received this message because you are subscribed to the
> Google Groups "Hobo Users" group. To view this discussion on the
> web visit
> https://groups.google.com/d/msg/hobousers/-/9DZac9RPNxgJ. To post
> to this group, send email to hobo...@googlegroups.com. To
> unsubscribe from this group, send email to
> hobousers+...@googlegroups.com. For more options, visit
> this group at http://groups.google.com/group/hobousers?hl=en.

- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlBbGhEACgkQBPlUJ6RHaOSMoQCgpLQbZ9PduUlHcw9Pzj9yT+Yg
5IMAniqNJWVj3lFhyUXXiM/VT6ZNecJJ
=2jET
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages