henkvantijen
12/16/2006 1:36:00 AM
Hi,
I started experimenting with RoR and came across the raw support for
form elements, if the input element is not bound to a Active Record
object. In my case, I was puzzled that I could find no better than this
for a set of filter checkboxes on top of a listing:
<%= check_box_tag :indexes, 1, checked = @indexes %> Indexes
<%= check_box_tag :stocks, 1, checked = @stocks %> Stocks
<%= check_box_tag :rates, 1, checked = @rates %> Rates
In the controller I also need some plumbing to connect the params to
the proper vars:
@stocks = params[:stocks]
@indexes = params[:indexes]
@rates = params[:rates]
Not very DRY.
In contrast, for an input element (without _tag) that I can bind to an
AR object, I only have to say
<%= text_field 'prediction', 'predicted_value' %>
and I don't need the plumbing: the binding is 2-way automagically.
Q: Is there some way to say something like
<%= check_box_tag :params :indexes %> Indexes
if I want to bind the input element to the previous form value, and
<%= check_box_tag :session :indexes %> Indexes
if I want to bind the input element 2-way to the session var ?
So perhaps what I am saying is, lets use a :binding_type key, that
defaults to active record:
<%= text_field 'prediction', 'predicted_value' %> # is default
case of next line
<%= text_field :binding_type => :active_record, 'prediction',
'predicted_value' %>
<%= text_field :binding_type => :params, 'predicted_value' %> #
2-way
<%= text_field :binding_type => :sessions, 'predicted_value' %> #
2-way
<%= check_box :binding_type => :sessions, :indexes %> # 2-way
and so on.
Hey, I am new to RoR, so I may have these wild ideas, okay?