希望有人能帮助我。目前正在开发一个需要一种奇怪功能的RoR项目。Rails,允许用户创建一个将被其他用户使用的表单
基本上,我有两种类型的用户User和Researcher。用户可以创建表单,这些表单存储在数据库中并由研究人员填写。
我有这个基本架构
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
因此,用户创建形式和form_fields和研究员然后记录并设有这种形式
<% 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 %>
所以结果存储在结果表和那是。
尝试允许用户在每个form_field上设置验证时,我可以看到自己遇到了麻烦。
任何人有这个问题的任何经验?
我想建立这样的事情,你发现什么是最好的方法? – JoeChin 2012-08-05 19:43:29