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)
It's all working, but then I tried to do it the rest way. So, i considered
added new resource called FlightCancellation, but I don't want it to
represent any database model. So it looks like this
> class FlightCancellation
>
> attr_reader :flight
>
>
>
> def initialize(flight)
>
> @flight = flight
>
> end
>
>
>
> end
>
>
And then in my FlightCancellations controller, I've something like this
>
class FlightCancellationsController < ApplicationController
def create
cancelation = params[:flight_cancelation]
flight = cancelation.flight
flight.cancel_flight
redirect_to :back, :notice => 'Flight was cancelled'
end
end
In routes.rb i have
> resources :flight_cancelations, :only => :create
And now, i'm confused about how to embbed it in my view ? I was trying to
do it like this
> <% @flights.each do |flight| %>
>
> <tr>
>
> <td><%= flight.from %></td>
>
> <td><%= flight.to %></td>
>
> <td><%= link_to 'Show', flight %></td>
>
> <td><%= link_to 'Edit', edit_flight_path(flight) %></td>
>
> <td><%= link_to 'Destroy', flight, method: :delete, data: { confirm:
>> 'Are you sure?' } %></td>
>
> <td>
>
> <%= form_for FlightCancelation.new(flight) do |f| %>
>
> <%= f.submit_tag 'Cancel that flight' %>
>
> <% end %>
>
> </td>
>
> </tr>
>
> <% end %>
>
>
Could anybody tell me how can I achive this, and if my way of thinking is
right ?
Thanks in advance, Mateusz Urban
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/9f27bdeb-1388-40ba-9f42-bf1e4c4c88ec%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.