Message from discussion
staying RESTful and triggering actions without saving a record.
Received: by 10.101.179.39 with SMTP id g39mr251596anp.36.1274181147837;
Tue, 18 May 2010 04:12:27 -0700 (PDT)
X-BeenThere: rubyonrails-talk@googlegroups.com
Received: by 10.101.11.8 with SMTP id o8ls2689149ani.6.p; Tue, 18 May 2010
04:11:59 -0700 (PDT)
Received: by 10.101.168.20 with SMTP id v20mr1928733ano.43.1274181119764;
Tue, 18 May 2010 04:11:59 -0700 (PDT)
Received: by 10.101.168.20 with SMTP id v20mr1928732ano.43.1274181119729;
Tue, 18 May 2010 04:11:59 -0700 (PDT)
Return-Path: <aaron.pfei...@gmail.com>
Received: from mail-gx0-f200.google.com (mail-gx0-f200.google.com [209.85.217.200])
by gmr-mx.google.com with ESMTP id 18si588822gxk.3.2010.05.18.04.11.59;
Tue, 18 May 2010 04:11:59 -0700 (PDT)
Received-SPF: pass (google.com: domain of aaron.pfei...@gmail.com designates 209.85.217.200 as permitted sender) client-ip=209.85.217.200;
Received: by mail-gx0-f200.google.com with SMTP id 24so418025gxk.3
for <rubyonrails-talk@googlegroups.com>; Tue, 18 May 2010 04:11:59 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.150.247.2 with SMTP id u2mr400700ybh.48.1274181119687; Tue, 18
May 2010 04:11:59 -0700 (PDT)
Received: by m33g2000vbi.googlegroups.com with HTTP; Tue, 18 May 2010 04:11:59
-0700 (PDT)
Date: Tue, 18 May 2010 04:11:59 -0700 (PDT)
In-Reply-To: <854102bb-66b5-47ac-a8b1-17ebf380d7a4@o12g2000vba.googlegroups.com>
X-IP: 24.61.15.159
References: <854102bb-66b5-47ac-a8b1-17ebf380d7a4@o12g2000vba.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4
(KHTML, like Gecko) Chrome/5.0.375.29 Safari/533.4,gzip(gfe)
Message-ID: <ed0dc3b2-53f5-4ef0-bffd-99700ed2bfed@m33g2000vbi.googlegroups.com>
Subject: [Rails] Re: staying RESTful and triggering actions without saving a
record.
From: Aaron Pfeifer <aaron.pfei...@gmail.com>
To: "Ruby on Rails: Talk" <rubyonrails-talk@googlegroups.com>
X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com:
domain of aaron.pfei...@gmail.com designates 209.85.217.200 as permitted
sender) smtp.mail=aaron.pfei...@gmail.com
X-Original-Sender: aaron.pfei...@gmail.com
Reply-To: rubyonrails-talk@googlegroups.com
Precedence: list
Mailing-list: list rubyonrails-talk@googlegroups.com; contact
rubyonrails-talk+owners@googlegroups.com
List-ID: <rubyonrails-talk.googlegroups.com>
List-Post: <http://groups.google.com/group/rubyonrails-talk/post?hl=en_US>,
<mailto:rubyonrails-talk@googlegroups.com>
List-Help: <http://groups.google.com/support/?hl=en_US>, <mailto:rubyonrails-talk+help@googlegroups.com>
List-Archive: <http://groups.google.com/group/rubyonrails-talk?hl=en_US>
Sender: rubyonrails-talk@googlegroups.com
List-Subscribe: <http://groups.google.com/group/rubyonrails-talk/subscribe?hl=en_US>,
<mailto:rubyonrails-talk+subscribe@googlegroups.com>
List-Unsubscribe: <http://groups.google.com/group/rubyonrails-talk/subscribe?hl=en_US>,
<mailto:rubyonrails-talk+unsubscribe@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hey Frank,
state_machine actually provides support for executing events using a
standard REST interface. Rather than calling the event method
directly (such as "release!"), you can set an the machine's event
attribute like so:
station.state_event =3D 'release'
station.save!
Any event that gets set in "state_event" will be validated and fired
when the record is saved. There's a full example (model, controller,
and views) of this here: http://github.com/pluginaweek/state_machine/tree/m=
aster/examples/rails-rest
Hope this helps!
-Aaron
On May 17, 10:50=A0pm, "frankjmat...@gmail.com" <frankjmat...@gmail.com>
wrote:
> the example i'm making uses state_machine because it's part of my
> current setup but this isnt a state_machine specific problem.
>
> i have a model called Station. it's an abstract concept for "an area
> in which work is performed"... when i'm using the app the Stations
> could be anything from "simulation terminal A" to "the lathe in
> building C"...
>
> each station has various properties (one of which is conveniently
> "state") and i would like to use buttons on my form (or links if it
> can be done in an xss safe way) to immediately change one of those
> properties... one button for example may be "release to floor" which
> when clicked would - in a non restful app - call the "release" action
> on the station controller. the release action would then take the
> station and call "release!" on it... however i want to accomplish this
> using standard actions.
>
> just using a text box and "saving" the record doesn't automatically
> fire the state-changing events (which i think is a good thing) AND
> that type of structure does not relate to my problem in a convenient
> way... there's a handful of cases where i just want to have a few
> buttons peppered in my form that when clicked, perform a direct action
> on my object without having to "invent" a bunch of non-standard
> actions..
>
> any tips?
> thank you much,
> - FJM
>
> --
> 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@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-talk+unsubscrib=
e@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/rubyo=
nrails-talk?hl=3Den.
--=20
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@=
googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyon=
rails-talk?hl=3Den.