Create Selection for a Year Range in Rails
I really love the simplicity of Rails when it comes to creating readable code and expressing your actual business requirements.
To give an example let's say you want to create an investment plan for an upcoming year. You can create the form and the selection with only two short lines (I'm using haml in the example):
= form_for @investment do |f|
= f.select(:year, 2013..2023)
Naturally you can take it further by defining the variables in your controller. In edit-view the selected year is automatically populated because you're using form_for.
Written by Marko Klemetti
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#