Skip to content

Instantly share code, notes, and snippets.

@soilforlifeforms
Created February 3, 2015 07:45
Show Gist options
  • Select an option

  • Save soilforlifeforms/b818244bb41a7d7cdeb3 to your computer and use it in GitHub Desktop.

Select an option

Save soilforlifeforms/b818244bb41a7d7cdeb3 to your computer and use it in GitHub Desktop.
class Answer < ActiveRecord::Base
belongs_to :question
belongs_to :questionnaire
#has_and_belongs_to_many :questions
has_one :input_type, :through => :question
belongs_to :gardener
accepts_nested_attributes_for :gardener
#accepts_nested_attributes_for :group
end
class AnswersController < ApplicationController
before_filter :authenticate_user!
def new
#1st you retrieve the group thanks to params[:group_id]
#2nd you build a new comment
#@question = question.new
@gardener_questionnaire = GardenerQuestionnaire.find(params[:gardener_questionnaire_id])
@questionnaire = @gardener_questionnaire.questionnaire
@answer= Answer.new
# @gardener_questionnaire= @gardener.build_gardener_questionnaire
end
def create
@gardener_questionnaire = GardenerQuestionnaire.(gardener_questionnaire_params)
@gardener_questionnaire.new(gardener_questionnaire_params)
if @gardener_questionnaire.save
redirect_to # STILL GOING TO GET THIS WORKING...;.
end
end
private
def gardener_questionnaire_params
params.require(:gardener_questionnaire).permit(:gardener_id, :questionnaire_id, gardener_attributes: [:id], questionnaire_attribues: [:id])
end
end
Started GET "/gardener_questionnaires/16/answers/new" for 127.0.0.1 at 2015-02-03 09:46:06 +0200
Started GET "/gardener_questionnaires/16/answers/new" for 127.0.0.1 at 2015-02-03 09:46:06 +0200
Processing by AnswersController#new as HTML
Processing by AnswersController#new as HTML
Parameters: {"gardener_questionnaire_id"=>"16"}
Parameters: {"gardener_questionnaire_id"=>"16"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 ORDER BY "users"."id" ASC LIMIT 1
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 ORDER BY "users"."id" ASC LIMIT 1
GardenerQuestionnaire Load (0.3ms) SELECT "gardener_questionnaires".* FROM "gardener_questionnaires" WHERE "gardener_questionnaires"."id" = $1 LIMIT 1 [["id", 16]]
GardenerQuestionnaire Load (0.3ms) SELECT "gardener_questionnaires".* FROM "gardener_questionnaires" WHERE "gardener_questionnaires"."id" = $1 LIMIT 1 [["id", 16]]
Questionnaire Load (0.3ms) SELECT "questionnaires".* FROM "questionnaires" WHERE "questionnaires"."id" = $1 LIMIT 1 [["id", 1]]
Questionnaire Load (0.3ms) SELECT "questionnaires".* FROM "questionnaires" WHERE "questionnaires"."id" = $1 LIMIT 1 [["id", 1]]
Question Load (0.5ms) SELECT "questions".* FROM "questions" INNER JOIN "questionnaires_questions" ON "questions"."id" = "questionnaires_questions"."question_id" WHERE "questionnaires_questions"."questionnaire_id" = $1 [["questionnaire_id", 1]]
Question Load (0.5ms) SELECT "questions".* FROM "questions" INNER JOIN "questionnaires_questions" ON "questions"."id" = "questionnaires_questions"."question_id" WHERE "questionnaires_questions"."questionnaire_id" = $1 [["questionnaire_id", 1]]
Rendered answers/new.html.erb within layouts/application (8.7ms)
Rendered answers/new.html.erb within layouts/application (8.7ms)
Completed 500 Internal Server Error in 64ms
Completed 500 Internal Server Error in 64ms
ActionView::Template::Error (undefined method `What is the length of your garden?' for #<Answer:0x007f9af3eccaf8>):
3:
4: <% @questionnaire.questions.each do |field| %>
5: <%= f.label field.question %>
6: <%= f.text_field field.question %>
7: <% end %>
8: <%= f.submit %>
9: <% end %>
app/views/answers/new.html.erb:6:in `block (2 levels) in _app_views_answers_new_html_erb__791067481078297384_70151747056640'
app/views/answers/new.html.erb:4:in `block in _app_views_answers_new_html_erb__791067481078297384_70151747056640'
app/views/answers/new.html.erb:1:in `_app_views_answers_new_html_erb__791067481078297384_70151747056640'
ActionView::Template::Error (undefined method `What is the length of your garden?' for #<Answer:0x007f9af3eccaf8>):
3:
4: <% @questionnaire.questions.each do |field| %>
5: <%= f.label field.question %>
6: <%= f.text_field field.question %>
7: <% end %>
8: <%= f.submit %>
9: <% end %>
app/views/answers/new.html.erb:6:in `block (2 levels) in _app_views_answers_new_html_erb__791067481078297384_70151747056640'
app/views/answers/new.html.erb:4:in `block in _app_views_answers_new_html_erb__791067481078297384_70151747056640'
app/views/answers/new.html.erb:1:in `_app_views_answers_new_html_erb__791067481078297384_70151747056640'
Rendered /Users/michaelfuller/.rvm/gems/ruby-2.1.2@rails-devise-pundit/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.3ms)
Rendered /Users/michaelfuller/.rvm/gems/ruby-2.1.2@rails-devise-pundit/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.3ms)
Rendered /Users/michaelfuller/.rvm/gems/ruby-2.1.2@rails-devise-pundit/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.9ms)
Rendered /Users/michaelfuller/.rvm/gems/ruby-2.1.2@rails-devise-pundit/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.9ms)
Rendered /Users/michaelfuller/.rvm/gems/ruby-2.1.2@rails-devise-pundit/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (57.8ms)
Rendered /Users/michaelfuller/.rvm/gems/ruby-2.1.2@rails-devise-pundit/gems/actionpack-4.1.4/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (57.8ms)
<%= form_for [@gardener_questionnaire, @answer] do |f| %>
<div class ="field">
<% @questionnaire.questions.each do |field| %>
<%= f.label field.question %>
<%= f.text_field field.question %>
<% end %>
<%= f.submit %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment