Skip to content

Instantly share code, notes, and snippets.

@wenbert
Created Jan 17, 2012
Embed
What would you like to do?
# GET /allergies/new
# GET /allergies/new.json
def new
@patient = Patient.find(params[:patient_id])
@allergy = @patient.allergies.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @allergy }
end
end
# GET /allergies/1/edit
def edit
@allergy = Allergy.find(params[:id])
end
# POST /allergies
# POST /allergies.json
def create
#@allergy = Allergy.new(params[:allergy])
@allergy = Patient.find(params[:patient_id]).allergies.build(params[:allergy])
respond_to do |format|
if @allergy.save
format.html { redirect_to patient_url(params[:patient_id]), notice: 'Allergy was successfully created.' }
#format.json { render json: @allergy, status: :created, location: @allergy }
else
format.html { render action: "new" }
format.json { render json: @allergy.errors, status: :unprocessable_entity }
end
end
end
AllergiesControllerTest:
FAIL should create allergy (0.40s)
"Allergy.count" didn't change by 1.
<3> expected but was
<2>.
test "should create allergy" do
assert_difference('Allergy.count') do
post :create, :post => @allergy, :patient_id => @allergy.patient_id
end
assert_redirected_to patients_path
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment