Skip to content

Instantly share code, notes, and snippets.

@puneetpandey
Created December 8, 2014 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puneetpandey/bafd8d78087d8713da79 to your computer and use it in GitHub Desktop.
Save puneetpandey/bafd8d78087d8713da79 to your computer and use it in GitHub Desktop.
# app/models
class User < ActiveRecord::Base
has_many :responses, dependent: :destroy
end
class Response < ActiveRecord::Base
has_one :report
has_many :points
belongs_to :user
end
class Report < ActiveRecord::Base
belongs_to :response
end
class Point < ActiveRecord::Base
belongs_to :response
end
# config/routes.rb
resources :users do
resources :responses do
resources :action_plans
end
end
# app/controllers/action_plans_controller.rb
class ActionPlansController < ApplicationController
before_filter :response
def new
@report = @response.build_report
5.times do
@response.points.build
end
end
private
def response
@response = current_user.responses.find(params[:id])
end
end
# http://localhost:3000/users/{:user_id}/responses/{:id}/action_plans/new
# Throws undefined method `committed?' for Response Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment