Building basic airline reservation system with Ruby on Rails

I’m 5 weeks into a training program that consists of Ruby, Ruby on Rails, Javascript, and React. I’m about the wrap up the 3-week module for Ruby on Rails, and chose to do a project that simulates a basic airline reservation system.
The requirements are minimal: have at least 3 classes (one being a join class) and use the CRUD methods with a Postgresql db. The processes of creating a reservation, reading an existing reservation, updating a reservation, and deleting a reservation are straightforward, but I’d like to jazz it up a bit for the presentation.

I have the code that eliminates a seat from the list of available seats once that seat is reserved, but I was wondering if there’s a way to incorporate a standard graphic that shows which seats are available (usually a green color) and which are taken (usually gray with an ‘X’). I’m thinking that the graphic would be an HTML form with embedded Ruby, and that each “seat” could be represented. The graphic would represent my Index.html.erb view, that would show the seat number and its status (occupied vs. available). I just can’t think of how this would be done, and I was wondering if anyone had an idea.

Daniel,

Wow, very nice. Where you taking your training?

It’s called Flatiron School. Their main “campus” is in Manhattan. I’m at one of their offices called Access Labs, in Brooklyn.

Hi, thank you very much for replying. I forgot to mention a biggie: that JS isn’t allowed. I can use CSS and Bootstrap but no JS allowed in this particular project (JS is our next module).

I sense that Ruby (on Rails) isn’t particularly geared for this type of interactivity.

If you want client-side "interactivity" JavaScript is the only option.

Rails is no different in this respect from any other server technology.

I sense that Ruby (on Rails) isn’t particularly geared for this type of interactivity.

It really is; It is not however geared for this type of interactivity if you need to exclude a key component of the ROR stack (javascript).

In fact - you’re not going to deliver your project at all without js.

Just have a look at the head section and you’ll see that you’re including a bunch of javascript which is core to the way that ROR works - even down to submitting forms and handling clicks!

that JS isn’t allowed. I can use CSS and Bootstrap but no JS allowed in this particular project (JS is our next module).

moving on from the fact that you are using javascript, you could ask what exactly they mean by this exclusion.

If they just want you to avoid writing explicit javacript that runs within the page (in /assets/javascripts), then they might allow partials.

this does use javascript - but typically only in a minimal way to replace a div or two with fresh html.

the js here lives in a view, but view.erb.js rather than view.erb.html

in your case, you could link up each seat to be a submit button on an individual form. (e.g. one form per seat), [you could also do each seat as a link with method: :post]

the partial would then either replace the whole plane, or replace the selected seat and the deselected seat.

this article gives some info on how this works

https://blog.codeship.com/unobtrusive-javascript-via-ajax-rails/

having said all that - it sounds like you might be jumping ahead. What you’re trying to do is probably going to be covered in your next module!

enjoy,

Rob

This is totally doable without javascript. Rails works perfectly fine without Javascript.

You will need to re-render the page from the server on any change/submit. That is ok (I suspect the exercise they are trying to teach you is that these sorts of interactions can be done in a server rendered way but when you get to the JS modules it will be easier and a better experience for the customer).

Each seat would need to be a submit button and on the server you would check the value of params[:commit] to validate. Once the seat is assigned/allocated you would re-render the page and show the correct styling.

<% @seats.each do |seat| %>

<% if seat.occupied %>

X

<% else %>

<%= f.submit seat.id, class: “available” %>

<% end %>

<% end %>

Rails works perfectly fine without Javascript.

I’m veering into the pedantic here…

Rails certainly can work fine without Javascript. As you say in this booking example, you can certainly just re-render the page completely on the server (even if it is ‘icky’!)

However to really use rails without javascript you would have to be careful to avoid the many standard features which are implemented using js.

e.g.

<%= link_to “test link”, test_path, method: :post %>

This submits via POST normally, but via GET if you disable javascript in your browser (or if you don’t include the standard js includes)

When I started writing Rails, it was normal to consider that a meaningful proportion of your customers would not have js, and write the app to handle that case.

Today, I certainly wouldn’t waste time coding for the ‘what if they don’t have js’ scenario.

cheers,

Rob

Rob, thank you for your reply. I understand what you’re saying about there really being no way to avoid using js. I feel like the combination I can look forward to is using js in the front and rails in the back.

I'm 5 weeks into a training program that consists of Ruby, Ruby on Rails, Javascript, and React. I'm about the wrap up the 3-week module for Ruby on Rails, and chose to do a project that simulates a basic airline reservation system.
The requirements are minimal: have at least 3 classes (one being a join class) and use the CRUD methods with a Postgresql db. The processes of creating a reservation, reading an existing reservation, updating a reservation, and deleting a reservation are straightforward, but I'd like to jazz it up a bit for the presentation.

I have the code that eliminates a seat from the list of available seats once that seat is reserved, but I was wondering if there's a way to incorporate a standard graphic that shows which seats are available (usually a green color) and which are taken (usually gray with an 'X'). I'm thinking that the graphic would be an HTML form with embedded Ruby, and that each "seat" could be represented. The graphic would represent my Index.html.erb view, that would show the seat number and its status (occupied vs. available). I just can't think of how this would be done, and I was wondering if anyone had an idea.

That looks like a really fun project. In the early 90's (yes, I'm old) I was commissioned to write a MacOS app for ticket sellers for venues where they could click on a similar seat layout to toggle their status from available to unavailable and be able to save the state and load it up later. (This was all in C at the time.)

Today I write software for property management in RoR to reserve dates for reservations for several hundred properties.

Anyway, for the purpose of your demo... you could cheat without using any JS and without having to reload the page if you just want a visual effect?

Something like this:

<html>
<head>
<style>
  background-color: yellow;
}

  background-color: pink;
}
</style>
</head>
<body>
<p><a href="#1">Seat</a></p>
<p><a href="#2">Seat</a></p>
</body>
</html>

Good luck!

Phil