#Answer_controller def index Hi! I have next problem.. Please help me understand how token works?? I need create each form for each user.. i mean, one user can see my form only once! (unique session)...
@answers=Hash.new if request.post? questions = Question.find(:all,:conditions=>"enabled=1") questions.each do |question| if params["answer_"+question.id.to_s] @answers[question.id]=params["answer_"+question.id.to_s] if ! Answer.create(:question_id=>question.id,:text=>params["answer_"+question.id.to_s]) flash[:error]="Can`t create answer!" end end end if !flash[:error] redirect_to :action=>"pass" return false end end
@questions = Question.find(:all,:conditions=>"enabled=1")
end
#view answer.html.erb <center>
<h1>Survey SIMPLE</h1>
<% form_tag do %> <table> <% @questions.each do |question| %> <tr style="vertical-align:top; text-align:left"> <th><%= question.text %></th> <td><%= text_area_tag "answer_#{question.id}",@answers[question.id], :cols=>"100", :rows=>"3" %></td> </tr> <% end %> </table> <%= submit_tag 'Pass survey' %> <% end %>
</center>