Rails Style Params in Python and Flask
Ruby on Rails does a great job of parsing arrays in form data and populating a params hash, for quick and easy access in your controllers. For instance Gives you params[:item] # => ["item 1", "item 2"] Flask doesn't do this work f...
Written by Sean Behan on 11/04/2018
Using Formtastic to Cleanly Create Nice Looking Forms in Rails
Forms can easily get cluttered when you're dealing with a lot of form fields... er, ERB tags. I've written about extending Rails form builders, which certainly goes along way to shrinking your views where forms are used. The plugin Formtastic is even bett...
Written by Sean Behan on 06/17/2012
Extending Rails Form Builders
Extending forms in Rails is simple and will greatly reduce the amount of code in your views. This example is taken right from the Agile Web Development book on Rails(2.1.*) with one minor tweak. I want to pass a label argument along with the field name so...
Written by Sean Behan on 06/17/2012
Trouble Using Attr_Accessor in Rails Models and Forms
You might use the attr_accessible method to create getters and setters for a class that has attributes which don't map directly to corresponding fields in a database. For example let's take the scenario where you are processing a credit card transaction. ...
Written by Sean Behan on 06/17/2012
Nested Has_one Relationship with Fields_for and Attr_accessible in Model Class
To make child attributes accessible to your model through a nested forms (Rails 2.3) you'll need to add the "#{child_class}_attributes" to the attr_accessible method in your parent class. If you don't use attr_accessible in your parent model (you would do...
Written by Sean Behan on 06/17/2012
Nested Attributes in a Form for Has_One Model Association in Rails
Just for reference... class Member < ActiveRecord::Base has_one :member_profile accepts_nested_attributes_for :member_profile end ...
Written by Sean Behan on 06/17/2012
Using Prototype to Access Form Data
Prototype has a powerful API for accessing and manipulating the Document Object Model, A.K.A the DOM. The following code will let you interact with a simple web form. Suppose we have a form that contains hidden/or locked inputs and they need to be update...
Written by Sean Behan on 06/17/2012