Building basic airline reservation system with Ruby on Rails

155 views
Skip to first unread message

Daniel Toma

unread,
Feb 10, 2019, 2:13:34 AM2/10/19
to Ruby on Rails: Talk
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.



Screen Shot 2019-02-09 at 4.47.22 PM.png


Hasan Diwan

unread,
Feb 10, 2019, 2:25:30 AM2/10/19
to rubyonra...@googlegroups.com
Daniel,

On Sat, 9 Feb 2019 at 23:13, Daniel Toma <toma...@gmail.com> wrote:
  I just can't think of how this would be done, and I was wondering if anyone had an idea.

While you could use ruby for this, a Javascript solution is going to be less heavy on the server. Simply define a class for blue and a class for red as follows in CSS:

.available { background-image("//location/of/green/image"); }
.taken { background-image("//location/of/red/image"); }
.na { background-image("//location/of/unavailable/image"}; }

Now that these are defined, you can set the class on submit using jquery's .addClass after removing the old one using .removeClass. Good luck, matey and let me know if you need further assistance.

--
If you wish to request my time, please do so using bit.ly/hd1AppointmentRequest.
Si vous voudrais faire connnaisance, allez a bit.ly/hd1AppointmentRequest.

Sent from my mobile device
Envoye de mon portable

Joe Guerra

unread,
Feb 10, 2019, 2:27:35 PM2/10/19
to Ruby on Rails: Talk
Wow, very nice.  Where you taking your training?  

Daniel Toma

unread,
Feb 10, 2019, 6:53:54 PM2/10/19
to Ruby on Rails: Talk
It's called Flatiron School.  Their main "campus" is in Manhattan.  I'm at one of their offices called Access Labs, in Brooklyn.

Daniel Toma

unread,
Feb 10, 2019, 6:55:22 PM2/10/19
to Ruby on Rails: Talk
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.

Hassan Schroeder

unread,
Feb 10, 2019, 7:05:12 PM2/10/19
to rubyonrails-talk
On Sun, Feb 10, 2019 at 3:55 PM Daniel Toma <toma...@gmail.com> wrote:
>
> 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.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Rob Jonson

unread,
Feb 11, 2019, 5:29:04 AM2/11/19
to Ruby on Rails: Talk

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

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

Rob Zolkos

unread,
Feb 11, 2019, 6:17:49 AM2/11/19
to rubyonra...@googlegroups.com
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 %>
      <div class="occupied">X</div>
    <% else %>
      <%= f.submit seat.id, class: "available" %>
    <% end %>
  <% end %>

--
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 rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6114bedb-e26d-4da1-b958-bc7efd99ada3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob Jonson

unread,
Feb 11, 2019, 6:37:34 AM2/11/19
to rubyonra...@googlegroups.com
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







You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/wgTcZ7C8mho/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.

To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--





Hobbyist Software is a trading name of Hobbyist Software Limited. Registered office 12 Fraley Rd, Bristol, BS93BS. Registered in England. Company no:7876492

Daniel Toma

unread,
Feb 12, 2019, 7:44:49 PM2/12/19
to Ruby on Rails: Talk
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.

Phil Edelbrock

unread,
Feb 12, 2019, 9:00:21 PM2/12/19
to rubyonra...@googlegroups.com
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>
a:visited {
background-color: yellow;
}

a:link {
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

Reply all
Reply to author
Forward
0 new messages