# The final hangup before this site goes to live beta and it i

**URL:** <https://www.ruby-forum.com/t/the-final-hangup-before-this-site-goes-to-live-beta-and-it-i/225945>\
**Category:** Rails\
**Created:** [April 16, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/the-final-hangup-before-this-site-goes-to-live-beta-and-it-i/225945 "2007-04-16T21:57:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [April 16, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/the-final-hangup-before-this-site-goes-to-live-beta-and-it-i/225945/1 "2007-04-16T21:57:34Z")

</div>

Ok everyone. I appreciate your time if you are looking at this, as  
this site is being setup to assist veterans who are having trouble  
with the health care system through the VA. And as I said, we are  
pretty close at this point to going live beta so if you can help me  
over this hump it would be extremely appreciated.

We have a form setup that asks the user to select a date when  
treatment began and then when treatment ended. After that they fill  
out a free text field explaining what kind of problems they  
experienced during their treatment. Then they submit it.

After that you go to user stories to view the stories submitted by  
everyone. Except we are getting an error when we try to open this page  
The error is posted below, and also the code from the models and  
controllers and rhtml files. I REALLY would appreciate any help in  
resolving this, so that I can put it into open beta, and then get it  
out to hopefully help make the nation aware of what is going on within  
the VA healthcare system.

Thank you for your time,

Dave

P.S. if you spot the problem could you provide easy to understand  
steps to resolve it?

Error from the page:

NoMethodError in Admissions#index

Showing app/views/admissions/\_admission.rhtml where line #2 raised:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.treatment\_start

Extracted source (around line #2):

1:

  
2: date: \<%=admission.treatment.treatment\_start-%\>  
  
3: story: \<%=admission.treatment.description-%\>  
4: \<%= debug(admission) %\>  
5: \<%= debug(admission.treatment)%\>

\_admission.rhtml

date: \<%=admission.treatment.treatment\_start-%\>  
story: \<%=admission.treatment.description-%\> \<%= debug(admission) %\> \<%= debug(admission.treatment)%\>

treatment.rb (model)

class Treatment \< ActiveRecord::Base  
acts\_as\_rateable

belongs\_to :user  
belongs\_to :condition  
belongs\_to :treatable, :polymorphic=\>true  
belongs\_to :doctor\_type

validates\_presence\_of :symptoms\_start

def temp\_rating=(temp\_rating)  
@rating=temp\_rating  
end

def temp\_rating  
@rating  
end

end

admission.rb (model)

class Admission \< ActiveRecord::Base  
has\_one :treatment, :as=\>:treatable  
belongs\_to :hospital  
end

treatments\_controller.rb

class TreatmentsController \< ApplicationController  
requires\_authentication :using =\> :authenticate,  
:include =\> [:new, :create, :update, :edit],  
:realm =\> ‘Unburdenus’

# GET /treatments

# GET /treatments.xml

def index  
@treatments = Treatment.find(:all)

```
respond_to do |format|
  format.html # index.rhtml
  format.xml { render :xml => @treatments.to_xml }
end

```

end

# GET /treatments/1

# GET /treatments/1.xml

def show  
@treatment = Treatment.find(params[:id])

```
respond_to do |format|
  format.html # show.rhtml
  format.xml { render :xml => @treatment.to_xml }
end

```

end

# GET /treatments/new

def new  
@user = User.current\_user  
@treatment = Treatment.new  
@stylesheet\_includes = [‘reset-fonts-  
grids’,‘default’,‘glenn’,‘datebocks\_engine’, ‘calendar-blue’]  
@javascript\_includes =  
[“prototype”,“scriptaculous”,‘moo.fx.js’,‘accordion’,‘application’,“datebocks\_engine”,  
“calendar”, “lang/calendar-en”, “calendar-setup”,“fckeditor/  
fckeditor”]  
end

# GET /treatments/1;edit

def edit  
@treatment = Treatment.find(params[:id])  
end

# POST /treatments/1;rate

def rate  
if params[:id].nil?  
@treatment = Treatment.new  
@treatment.temp\_rating=params[:rating]  
else  
@treatment = Treatment.find(params[:id])  
Rating.delete\_all([“rateable\_type = ‘Treatment’ AND rateable\_id  
= ? AND user\_id = ?”, @treatment.id, User.current\_user.id])  
@treatment.add\_rating Rating.new(:rating =\>  
params[:rating], :user\_id =\> User.current\_user.id)  
end  
end

# POST /treatments

# POST /treatments.xml

def create  
@hospital = Hospital.find\_or\_create\_by\_name(params[:hospital]  
[:name])  
@admission = Admission.new(:hospital=\>@hospital)  
@treatment = Treatment.new(params[:treatment])  
@treatment.condition =  
Condition.find\_or\_create\_by\_name(params[:condition][:name])  
@treatment.user = User.current\_user  
@treatment.treatable = @admission  
respond\_to do |format|  
if @treatment.save  
flash[:notice] = ‘Treatment was successfully created.’  
format.html { redirect\_to user\_url(User.current\_user) }  
format.xml { head :created, :location =\>  
treatment\_url(@treatment) }  
else  
format.html {  
@stylesheet\_includes = [‘reset-fonts-  
grids’,‘default’,‘glenn’,‘datebocks\_engine’, ‘calendar-blue’]  
@javascript\_includes =  
[“prototype”,“scriptaculous”,‘moo.fx.js’,‘accordion’,‘application’,“datebocks\_engine”,  
“calendar”, “lang/calendar-en”, “calendar-setup”,“fckeditor/  
fckeditor”]  
render :action =\> “new”  
}  
format.xml { render :xml =\> @treatment.errors.to\_xml }  
end  
end  
end

# PUT /treatments/1

# PUT /treatments/1.xml

def update  
@treatment = Treatment.find(params[:id])

```
respond_to do |format|
  if @treatment.update_attributes(params[:treatment])
    flash[:notice] = 'Treatment was successfully updated.'
    format.html { redirect_to treatment_url(@treatment) }
    format.xml { head :ok }
  else
    format.html { render :action => "edit" }
    format.xml { render :xml => @treatment.errors.to_xml }
  end
end

```

end

# DELETE /treatments/1

# DELETE /treatments/1.xml

def destroy  
@treatment = Treatment.find(params[:id])  
@treatment.destroy

```
respond_to do |format|
  format.html { redirect_to treatments_url }
  format.xml { head :ok }
end

```

end  
end

admissions\_controller.rb

class AdmissionsController \< ApplicationController

# GET /admissions

# GET /admissions.xml

def index  
@admissions = Admission.find(:all)

```
respond_to do |format|
  format.html {
    @stylesheet_includes = ['reset-fonts-grids','default','glenn']
  }
  format.xml { render :xml => @admissions.to_xml }
end

```

end

# GET /admissions/1

# GET /admissions/1.xml

def show  
@admission = Admission.find(params[:id])

```
respond_to do |format|
  format.html # show.rhtml
  format.xml { render :xml => @admission.to_xml }
end

```

end

# GET /admissions/new

def new  
@admission = Admission.new  
end

# GET /admissions/1;edit

def edit  
@admission = Admission.find(params[:id])  
end

# POST /admissions

# POST /admissions.xml

def create  
@admission = Admission.new(params[:admission])

```
respond_to do |format|
  if @admission.save
    flash[:notice] = 'Admission was successfully created.'
    format.html { redirect_to admission_url(@admission) }
    format.xml { head :created, :location =>

```

admission\_url(@admission) }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @admission.errors.to\_xml }  
end  
end  
end

# PUT /admissions/1

# PUT /admissions/1.xml

def update  
@admission = Admission.find(params[:id])

```
respond_to do |format|
  if @admission.update_attributes(params[:admission])
    flash[:notice] = 'Admission was successfully updated.'
    format.html { redirect_to admission_url(@admission) }
    format.xml { head :ok }
  else
    format.html { render :action => "edit" }
    format.xml { render :xml => @admission.errors.to_xml }
  end
end

```

end

# DELETE /admissions/1

# DELETE /admissions/1.xml

def destroy  
@admission = Admission.find(params[:id])  
@admission.destroy

```
respond_to do |format|
  format.html { redirect_to admissions_url }
  format.xml { head :ok }
end

```

end  
end

---

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [April 17, 2007, 12:07am UTC](https://www.ruby-forum.com/t/the-final-hangup-before-this-site-goes-to-live-beta-and-it-i/225945/2 "2007-04-17T00:07:53Z")

</div>

Hmmm… you’re getting that error because somehow, the @admission  
you’ve  
selected from the database does not have a treatment associated with it.  
It could be that you just have a leftover record in your system without  
a  
treatment.

You can overcome this several ways…

first, do a check in that partial

\<% unless @admission.treatment.nil? %\>  
date: \<%=admission.treatment.treatment\_start-%\>  
  
story: \<%=admission.treatment.description-%\>  
\<% end %\>

Or you can take the lazy (but as I understand it, expensive) way out and  
just do  
date: \<%=admission.treatment.treatment\_start rescue “No start  
date”-%\>  
  
story: \<%=admission.treatment.description rescue “no story”-%\>

I’m going to go out on a limb here and say that you have unit tests in  
place  
to ensure that your associations between treatments and admissions are  
working… so I bet it has something to do with your data.

---

<div class="post-metadata">

**Author:** ![wheresdave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/6a8cbe/32.png) [@wheresdave](https://www.ruby-forum.com/u/wheresdave)\
**Post date:** [September 25, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/the-final-hangup-before-this-site-goes-to-live-beta-and-it-i/225945/3 "2007-09-25T23:05:30Z")

</div>

Brian,

Thank you so much, I am now able to view that page, and start moving  
towards final completion. I may push it out to open beta tonight so  
that the rails newsgroup can view it and give some feedback.

Thank you,

Dave
