I have encountered what’s beginning to look like a classic problem with
Rails: validating non-model forms. Under what circumstances do you need
to use non-model components in a model-backed form? I need to for credit
card processing: I want to save information like the customer’s phone
number but I don’t want to save their credit card number for security
reasons. Apparently, this situation also comes up when setting up basic
search forms for your website as well
Ryan didn’t address it.
Essentially we’re looking at this situation in the checkout view:
<% form_for(@checkout, :url => “/checkout”) do |f| %>
<%= f.text_field :first_name %>
<%= f.text_field :last_name %>
<%= text_field(:cc, :card) %>
<%= text_field(:cc, :expiration_date) %>
<% end %>
But when the model is saved, the :card and :expiration_date fields are
not validated because they’re not part of the model (they are accessed
using params[:cc][:card] and params[:cc][:expiration_date]).
All this code works - I just need to validate my credit card stuff! How
do I do this? I know I’m not the first guy to run into this problem.
Thank you for any suggestions!