Hey Guys,
Hope someone can help me out. Currently working on a RoR project that needs a strange kind of functionality.
Basically, I have two types of users named User and Researcher. Users can create forms and these forms are stored in the db and filled in by researchers.
I have this basic schema
create_table "form_fields", :force => true do |t|
t.string "name"
t.string "form_field_type"
t.integer "form_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "forms", :force => true do |t|
t.integer "visit_id"
t.string "name"
t.integer "form_category_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "researchers", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token"
t.string "remember_token"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "researchers", ["email"], :name => "index_researchers_on_email", :unique => true
add_index "researchers", ["reset_password_token"], :name => "index_researchers_on_reset_password_token", :unique => true
create_table "results", :force => true do |t|
t.integer "form_id"
t.integer "subject_id"
t.string "form_field_name"
t.string "form_field_value"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
t.string "password_salt", :default => "", :null => false
t.string "reset_password_token"
t.string "remember_token"
t.datetime "remember_created_at"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
create_table "visits", :force => true do |t|
t.string "name"
t.integer "visit_order"
t.integer "study_id"
t.datetime "created_at"
t.datetime "updated_at"
end
So, a User creates the forms and form_fields and a researcher then logs in and is provided with this form
<% form_for [:researcher, @study, @subject, @visit, @form, Result.new] do |f| %>
<% @form.form_fields.each do |form_field| %>
<%= f.label form_field.name, :index => form_field.id %>
<%= f.hidden_field :form_field_name, :value=>form_field.name, :index => form_field.id %>
<%= f.text_field :form_field_value, :index => form_field.id %><br/>
<%= f.hidden_field :form_id, :value=>@form.id, :index => form_field.id %>
<%= f.hidden_field :subject_id, :value=>@subject.id, :index => form_field.id %>
<% end %>
<%= f.submit %>
<% end %>
So the result is stored in the results table and thats that.
I can see myself running into trouble when trying to allow users to set validations on each form_field.
Anybody have any experience with this problem?
Cheers,
Stuart