Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an input not related to the model with Formtastic

For a subscription form, I need to have a field that is not mapped to my User object.

This field is only used to ask the user for an invitation code, that is checked against an invitations list in the create action of the controller, but not saved anywhere, and without a relation to this User object.

I tried :

<%= semantic_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= f.input :invitation_key, :input_html => {:name => 'invitation_key', :id => 'invitation_key'} %>

But it does not work.

What is the correct way to do this with Formtastic ?

like image 449
Renaud Chaput Avatar asked May 05 '12 21:05

Renaud Chaput


1 Answers

You could just do something like this instead of the f.input. I couldn't find a way to do it with a Formtastic-specific helper:

<li>
    <%= label_tag 'Invitation Key' %>
    <%= text_field_tag :invitation_key %>
</li>
like image 130
Melinda Weathers Avatar answered Oct 24 '22 22:10

Melinda Weathers