<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.1.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: acts_as_state_machine and variable initial states</title>
	<link>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/</link>
	<description>Because programming should be fun</description>
	<pubDate>Fri, 12 Mar 2010 13:31:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>

	<item>
		<title>By: macournoyer</title>
		<link>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-669</link>
		<author>macournoyer</author>
		<pubDate>Wed, 10 Sep 2008 18:58:51 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-669</guid>
					<description>Hey Frank,

I think the best way is:

def create
  user = User.new(params[:user]) 
  user.enable!
end

enable! calls save, no hacks and pretty explicit.
Changing a class attribute like this is not good practice and would prevent your app from being multi-thread amongst other things.</description>
		<content:encoded><![CDATA[<p>Hey Frank,</p>
<p>I think the best way is:</p>
<p>def create<br />
  user = User.new(params[:user])<br />
  user.enable!<br />
end</p>
<p>enable! calls save, no hacks and pretty explicit.<br />
Changing a class attribute like this is not good practice and would prevent your app from being multi-thread amongst other things.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-670</link>
		<author>Frank</author>
		<pubDate>Wed, 10 Sep 2008 19:00:55 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-670</guid>
					<description>Marc, thanks for your input. Feel a bit silly now ;)

However I still wonder why it isn't possible to bypass the initial state specified in the model. I'd prefer if I could just send the &#34;state&#34; attribute among the rest like that : User.new(:name =&#62; &#34;blabla&#34;, :state =&#62; &#34;enabled&#34;)</description>
		<content:encoded><![CDATA[<p>Marc, thanks for your input. Feel a bit silly now <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
However I still wonder why it isn&#8217;t possible to bypass the initial state specified in the model. I&#8217;d prefer if I could just send the &quot;state&quot; attribute among the rest like that : User.new(:name =&gt; &quot;blabla&quot;, :state =&gt; &quot;enabled&quot;)</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-671</link>
		<author>Frank</author>
		<pubDate>Wed, 10 Sep 2008 19:43:00 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-671</guid>
					<description>Hmm... interesting. I started experiencing some weird deadlock errors as soon as I tried what you said Marc. I am too lazy to check the plugin code but I would guess it does something special with the "!" events. Or maybe it's something completely unrelated... still checking the issue.</description>
		<content:encoded><![CDATA[<p>Hmm&#8230; interesting. I started experiencing some weird deadlock errors as soon as I tried what you said Marc. I am too lazy to check the plugin code but I would guess it does something special with the &#8220;!&#8221; events. Or maybe it&#8217;s something completely unrelated&#8230; still checking the issue.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Cyberfox</title>
		<link>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-673</link>
		<author>Cyberfox</author>
		<pubDate>Thu, 11 Sep 2008 01:12:02 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-673</guid>
					<description>Greetings,
I believe the reason you can't do that is that you'd be jumping to a middle state of a state machine.  Essentially you'd be bypassing any code that was set up to happen during transitions.

The system needs to trigger when you transition from (for example) :free to :paid, so it can provision you with the appropriate features.

In order to trigger on transition between states, you have to have a consistent starting state.

Think of it as stateful integrity, a term that has only two Google hits, so I consider myself to have made it up just now, for just this purpose.  :)

--  Morgan</description>
		<content:encoded><![CDATA[<p>Greetings,<br />
I believe the reason you can&#8217;t do that is that you&#8217;d be jumping to a middle state of a state machine.  Essentially you&#8217;d be bypassing any code that was set up to happen during transitions.</p>
<p>The system needs to trigger when you transition from (for example) :free to :paid, so it can provision you with the appropriate features.</p>
<p>In order to trigger on transition between states, you have to have a consistent starting state.</p>
<p>Think of it as stateful integrity, a term that has only two Google hits, so I consider myself to have made it up just now, for just this purpose.  <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#8211;  Morgan</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-674</link>
		<author>Frank</author>
		<pubDate>Thu, 11 Sep 2008 12:48:41 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-674</guid>
					<description>Cyberfox,

good call, it makes sense. So basically I should redesign my "user state machine"  to have just 1 initial state.

Maybe have the following states :

All new users could be : new (initial)
Unapproved users : unapproved
Enabled users : enabled
Disabled users : disabled

And the events :
approve! (from :unapproved to :enabled)
enable! (from :new to :enabled)
disable! (from :enabled to :disabled and from :unapproved to :disabled)

I guess that would be better than having more than 1 initial states. Any thoughts?</description>
		<content:encoded><![CDATA[<p>Cyberfox,</p>
<p>good call, it makes sense. So basically I should redesign my &#8220;user state machine&#8221;  to have just 1 initial state.</p>
<p>Maybe have the following states :</p>
<p>All new users could be : new (initial)<br />
Unapproved users : unapproved<br />
Enabled users : enabled<br />
Disabled users : disabled</p>
<p>And the events :<br />
approve! (from :unapproved to :enabled)<br />
enable! (from :new to :enabled)<br />
disable! (from :enabled to :disabled and from :unapproved to :disabled)</p>
<p>I guess that would be better than having more than 1 initial states. Any thoughts?</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: pravs</title>
		<link>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-848</link>
		<author>pravs</author>
		<pubDate>Tue, 30 Jun 2009 14:33:56 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/acts_as_state_machine-and-variable-initial-states/#comment-848</guid>
					<description>Hello Frank,
I am bit confused 
Isn't it good way to use 
"User.write_inheritable_attribute :initial_state, :enabled" 
Because I want to assign the specific state (e.g. :xyz) initially only in few cases. And in other cases when i migrate from any other state to :xyz and have to perform some events which are not required in first case.
Therefore I cannot use 
User.xyz!  as this performs all the event actions when I do this.

So can anyone suggest me a good way to do this.
"User.write_inheritable_attribute :initial_state, :xyz"  serves my purpose but as someone has already said its not a good practice.</description>
		<content:encoded><![CDATA[<p>Hello Frank,<br />
I am bit confused<br />
Isn&#8217;t it good way to use<br />
&#8220;User.write_inheritable_attribute :initial_state, :enabled&#8221;<br />
Because I want to assign the specific state (e.g. :xyz) initially only in few cases. And in other cases when i migrate from any other state to :xyz and have to perform some events which are not required in first case.<br />
Therefore I cannot use<br />
User.xyz!  as this performs all the event actions when I do this.</p>
<p>So can anyone suggest me a good way to do this.<br />
&#8220;User.write_inheritable_attribute :initial_state, :xyz&#8221;  serves my purpose but as someone has already said its not a good practice.</p>
]]></content:encoded>
				</item>
</channel>
</rss>
