我如何允许用户创建调查

时间:2016-08-11 14:16:59

标签: ruby-on-rails ruby

过去两天,我已经陷入了大脑困境。我希望能够允许我的用户创建广告系列(与调查相同的概念),它将允许他们请求他们希望的某些数据,例如电子邮件地址。这将允许填写表格的人在输入电子邮件后继续并接收下载链接。输入的电子邮件应存储给创建要查看的广告系列的人员。

我采用嵌套表格的方式,但是我遇到了允许输入和保存电子邮件以供广告系列创建者查看的麻烦。

感谢任何帮助。

campaign.rb模型

class Campaign < ActiveRecord::Base belongs_to :user has_many :queries accepts_nested_attributes_for :queries end

query.rb模型

class Query < ActiveRecord::Base belongs_to :campaign has_many :results end

result.rb模型

class Result < ActiveRecord::Base attr_accessible :content, :email, :query_id belongs_to :query end

schema.rb

  create_table "campaigns", force: :cascade do |t|
t.string   "title"
t.text     "description"
t.integer  "user_id"
t.datetime "created_at",  null: false
t.datetime "updated_at",  null: false
 end

  add_index "campaigns", ["user_id"], name: "index_campaigns_on_user_id", using: :btree

  create_table "queries", force: :cascade do |t|
t.integer  "campaign_id"
t.text     "content"
t.string   "email"
t.datetime "created_at",  null: false
t.datetime "updated_at",  null: false
end

  add_index "queries", ["campaign_id"], name: "index_queries_on_campaign_id", using: :btree

  create_table "results", force: :cascade do |t|
t.integer  "query_id"
t.text     "content"
t.string   "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

  add_index "results", ["query_id"], name: "index_results_on_query_id", using: :btree

campaign_controller.rb的一部分

  private
# Use callbacks to share common setup or constraints between actions.
def set_campaign
  @campaign = Campaign.find(params[:id])
end

def campaign_params
  params.require(:campaign).permit(:title, :description, :queries_attributes)
end

def query_params
  params.require(:query).permit(:content, :email, :campaign_id)
end

0 个答案:

没有答案