本文介绍了在formtastic中访问表单对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我正在制作一个调查应用程序.用户在后端选择一种表单类型,在前端显示为某种类型.当然,这只是理想情况.现在发生的是我无法访问 formtastic 正在为其构建表单的对象.我怎么能说question.kind"之类的东西?它只会以这种方式出错.这是我到目前为止所拥有的......
So I'm making a survey app. The users choose a type of form on the backend, and it displays as a certain type on the front end. That's only ideally, of course. What happens now is I can't access the object formtastic is building the form for. How can I say something like "question.kind"? It just makes an error that way. Here's what I have so far...
= semantic_form_for @survey, :url => "#", :html => { :method => "get" } do |f|
- for question in @survey.questions
= user_facing_question(f)
到目前为止,辅助辅助方法是这样的:
and the complementary helper method goes like this so far:
def user_facing_question(f)
f.inputs
end
推荐答案
您可以像这样访问表单的对象:
You can access the form's object like:
f.object
这篇关于在formtastic中访问表单对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!