[英]Using :collection and :include_blank in Formtastic. How to do it?
[英]Splitting and array using formtastic. Error: undefined method `map'
我试图将我的“问卷”表中的“选择”列转换为多个选择的单独字符串。
问卷调查负责人:
class QuestionnairesController < ApplicationController
def index
@questions = Questionnaire.find(params[:category_id])
#params[:category_id]= <%=category.id%>
@category = Category.find(params[:category_id])
@videos = VideoClue.find(params[:category_id])
###This finds all the questions from the question table by their category_id. Whenever I select a category, it matches the question related to the category
render :show
###render :show Renders Html page
end
def choose_answer
# binding.pry
@questions = Questionnaire.find(params[:id])
#params[:id] = /:id = /1
render :choose_answer
end
end
问卷模型:
class Questionnaire < ActiveRecord::Base
belongs_to :categories
end
Chose_answer.html.erb
<h1>Congrats You Hit The Choices Page!</h1>
<%= semantic_form_for @questions.choices do |c| %>
<%= c.inputs do %>
<%= c.input :choices, :as => :check_boxes , :collection =>
[@questions.choices].map(&:inspect).join(', ') %>
<%end%>
<%end%>
问卷表种子:
Questionnaire.create({question: "In that year did MTV (Music Television)
premiere and what was the first music video the channel aired?", choices:
["1982 Michael Jackson 'Bille Jean'", "1984 Madonna 'Like a virgn'", "1981
The Buggles 'Video Killed The Radio Star'"], correct_answer:"1981 The
Buggles 'Video Killed The Radio Star' ", category_id:1})
@ question.choices返回
["1982 Michael Jackson 'Bille Jean'", "1984
Madonna 'Like a virgn'", "1981 The Buggles 'Video Killed The Radio Star'"],
如何从选项列数组中分离字符串,并使用formtastic将字符串转换为多选择格式?
<%= c.input :choices, :as => :check_boxes , :collection => @questions.choices %>
应该在这里执行您想要的操作,如果它已经是数组IIRC,则无需修改它,除非我误会了情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.