On 23 May 2013 12:56, Mateusz Urban <
mateus...@gmail.com> wrote:
> Hi!
> Reading "Rails For .NET Developers" i started to consider the example of
> building the flight system with cancellations. So, I've generated flights
> scaffold and passengers scaffold and I'd like that we could cancel the
> flight and then, each of the passengers would be informed about that fact.
> So, firstly i've written a non-rest code and simply added "cancel_flight"
> method to my FlightsController and generated required routes in routes.rb.
> And it looks like this:
>>>
>>> def cancel_flight
>>>
>>> flight = Flight.find(params[:flight])
>>>
>>>
>>>
>>> flight.cancel_flight
>>>
>>>
>>>
>>> redirect_to flights_path
>>>
>>>
>>>
>>> end
>
> (where Flight model has a method cancel_flight, which of course knows what
> to do)
There is no need for a separate controller, one way would be to handle
it within the flights controller Edit action, using a url parameter or
the Submit button name to indicate that cancel is required rather than
edit.
However, REST should not be treated as a religion to which all
requirements must bow. I would say there is nothing wrong with what
you have done (provided that you have used a POST to do it).
Colin