Rails, Form Tag Helpers

This week at Flatiron we started to use Ruby on rails. The experience has been nothing short of amazing. This is coming off of a full week of learning and using Sinatra. Sinatra seems really great for lightweight projects but it was far too repetitive in what it asked of us coders to type out. I kept thinking to myself during the process, “There must be a better way of doing this?” Enter rails.

Rails is what you would call a web framework. Where in Sinatra you have to make everything from scratch rails offers something of a starter pack to your web application. At its heart rails is a set of Ruby code libraries that allows users to increase their productivity when creating a web application. In all honesty rails is too large a topic to discuss since and so that’s why I chose to focus in on one aspect.

As soon as I began learning about form tag helpers I was immediately elated. Finally a way to cut down on so much typing in my views folder! Here are a few tag forms that really caught my eye when reading through documentation.

Form Tags

We’re all familiar with forms both in real and digital world. We fill them out and then submit them somewhere. Form tags in rails are sometimes very much like helper methods where they have logic behind them that assumes where you want the information submitted to be sent.

Submit Tag: The submit tag is pretty straight-forward. It creates a submit button for the user to click, not too much going on besides the fact that it helps you cut down on text.

Text Field / Text Area Tag: These two tags create a text box for users to type into. A text field tag is meant for smaller chunks of text like usernames or emails. Text area tags usually take on longer texts for example a small description. Again this tag helps cut down on required typing thanks to ruby methods functioning in the background.

Form Tag: The form tag is a great helper tag for a couple reasons. It doesn’t require us to type out what method we want from it, it assumes that we want to submit the form through means of a post. It also automatically generates an authenticity token to help keep our users safe from hackers. Additionally it also helps on cutting down some text that we would otherwise have to type out.

Tagless
with tags

Date Field Tag: The date field tag creates a text field of a month/date/year. This is a very useful tool and I could see it being essential to some web apps. Along with the date field tag are the week and month field tag.

Select Tag: The select form tag creates a drop down menu that can take in as many parameters as you would like to give it. It can also offer a multiple choice selection box if you set the multiple option to true.

Password Field Tag: The password field tag is pretty self explanatory. It creates a text box that hides the characters that a user types in. We’re all very familiar with this whenever we login to our faceboooks or email.

Here are just a few form tags that I found to be very useful in the future when I begin diving deeper into my rails journey. I’ll be updating this blog post as I come to use more tags or use them in different ways!

Like what you read? Give Diego Dorado a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.