Guest User

Untitled

a guest
Apr 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. ## views/questionaires/new
  2.  
  3.  
  4. <%= error_messages_for :questionaire %>
  5.  
  6. <% form_for(@questionaire) do |f| %>
  7.  
  8. . . .
  9.  
  10.  
  11. <%= hidden_field_tag "time_started", Time.now %>
  12.  
  13. <p>
  14. <%= f.submit "Create" %>
  15. </p>
  16. <% end %>
  17.  
  18. ## controllers/questionaires_controller.rb
  19.  
  20. def create
  21. @questionaire = current_user.build_questionaire(params[:questionaire])
  22. @questionaire.time_taken = Time.now - params[:time_started]
  23.  
  24. respond_to do |format|
  25. if @questionaire.save
  26. flash[:notice] = 'Questionaire was successfully created.'
  27. format.html { redirect_to( :controller => "account", :action => "logout") }
  28. format.xml { render :xml => @questionaire, :status => :created, :location => @questionaire }
  29. else
  30. format.html { render :action => "new" }
  31. format.xml { render :xml => @questionaire.errors, :status => :unprocessable_entity }
  32. end
  33. end
  34. end
Add Comment
Please, Sign In to add comment