RoR:Collection_select不起作用

时间:2016-09-15 21:41:42

标签: ruby-on-rails ruby database

已更新

这方面的官方文件不是最好的,有点令人困惑。我正在从反馈表中收集选项并将其呈现在表单的下拉列表中,然后将它们保存在一个名为" answers"的表中。和列名为" feedback_request"使用collection_select:

<%= f.collection_select :feedback_request, Feedback.order(:feedback_option), :id, :feedback_request, {prompt: "Feedback"}, {class: "select large-1 behaviourForm"} %>

答案表:

  create_table "answers", force: :cascade do |t|
        t.integer  "user_id",             limit: 4
        t.string   "subject",             limit: 4
        t.string   "source",              limit: 45
        t.text     "description",         limit: 65535
        t.string   "significance",        limit: 45
        t.string   "feedback_request"
        t.datetime "created_at",                        null: false
        t.datetime "updated_at",                        null: false
    end

  add_index "answers", ["feedback_request"], name: "feedback_index"
  add_index "answers", ["significance"], name: "signif_index"
  add_index "answers", ["source"], name: "source_index"
  add_index "answers", ["subject"], name: "FK_HOM_MOD_idx"
  add_index "answers", ["user_id"], name: "teacher_answer_index"

反馈表

create_table "feedback", force: :cascade do |t|
    t.string "feedback_option", limit: 45
  end

关系

feedback.rb

class Feedback < ActiveRecord::Base
    self.table_name = 'feedback'
    has_many :answers, :class_name => 'Answer'
end

answer.rb

belongs_to :feedback, :class_name => 'Feedback', :foreign_key => :feedback_request

表格(根据要求):

         <thead>
              <tr>
                <% if current_user.teacher? %>
                <th style="width:5%;", bgcolor="#313E4E" ></th>
                <th bgcolor="#313E4E"><font color="#FFFFFF">Answer Title</font></th>
                <% else %>
                <th bgcolor="#313E4E"><font color="#FFFFFF">Subject</font></th>
                <% end %>
                <th bgcolor="#313E4E"><font color="#FFFFFF">Source</font></th>

                <th bgcolor="#313E4E"><font color="#FFFFFF"><%= sort_link(@q, :created_at, "Assigned/Scheduled") %></font></th>
                <th bgcolor="#313E4E"><font color="#FFFFFF"><%= sort_link(@q, :Due, "Due") %></font></th>
              </tr>
              </thead>
              <tfoot>
              </tfoot>
              <%= form_tag destroy_multiple_answers_path, method: :delete do %>
              <% @answers.each do |answer| %>
              <tbody>
              <tr>
                <% if current_user.teacher? %>
                <td><%= check_box_tag "answer[id][]", answer.id, class: "narrowtr" %></input></td>
                <td height="1"><font color="#000000"><%= link_to answer.subject, answer, class: "blackLink" %></font></td>
                <% else %>
                <td height="1"><%= answer.subject %></td>
                <% end %>
                <td height="1"></td>
                <td height="1"><%= answer.created_at %></td>
                <td height="1"><%= answer.Due %></td>
              </tr>
              </tbody>
              <% end %>
            </table>

这在提交时给出了以下错误:

**undefined method `feedback_request' for #<Feedback id: 1, feedback_option: "Curriculum Management">**

非常感谢任何指导。

0 个答案:

没有答案