I am passing hard time with ruby on rails …I was trying to count the
average of a whole table…at first I calculated avarage of eah
column
then average of the average values but it is giving me an error- here
are
my codes and error-
error-
NoMethodError in Rate_schools#index
Showing /home/vmuser/workspace/project3
-3/app/views/rate_schools/index.html.erb where line #36 raised:
undefined method `+’ for nil:NilClass
Extracted source (around line #36):
33:
34:
35:
36: Average
<%=((@avg1+@avg2+@avg3+@avg4+@avg5+@avg6+@avg7+@avg8)/8)%>
37: <% end %>
38:
39:
codes In controller:
def index
@school=School.find(params[:id])
@rate_school [email protected]_schools.build
@[email protected]_schools.average(:library)
@[email protected]_schools.average(:careercenter)
@[email protected]_schools.average(:location)
@[email protected]_schools.average(:food)
@[email protected]_schools.average(:healthcenter)
@[email protected]_schools.average(:studentactivities)
@[email protected]_schools.average(:facilities)
@[email protected]_schools.average(:internetspeed)
codes in index :
<% if !@school.rate_schools.blank? %>
Average
<%=((@avg1+@avg2+@avg3+@avg4+@avg5+@avg6+@avg7+@avg8)/8)%>
<% end %>
</tr>
</table>