I have an app with the following models:
course
belongs_to :semester
semester
has_many: courses
belongs_to :education
education
has_many :semesters
In my old app (rails 1.2.6) I was able to access variables via
controller
@courses = Course.find(:all)
view file:
<% for course in @courses %>
<%= course.name %> <- this line works
<%= course.semester.name %> <- this is now broke
<%= course.semester.education.name %> <-this is now broken.
When upgrading to rails 2.2.2 all this is broken.
What changed?
I only changed the enviroment.rb to rails 2.2.2 and did rake
rails:upgrade
On Mar 6, 9:35 am, “[email protected]” [email protected]
wrote:
When upgrading to rails 2.2.2 all this is broken.
In what way is it broken ? What happens ?
Fred
Error:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.name
the view
<%= link_to course.semester.name, :controller =>
‘reporting’, :action => ‘new’, :id => course.id %>
the database:
On Mar 6, 11:35 am, Frederick C. [email protected]
in that view, does
<%= course.class %>
<%= course.semester_id %>
give you something like this
Course
32
Error:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.name
the view
<%= link_to course.semester.name, :controller =>
‘reporting’, :action => ‘new’, :id => course.id %>
the database:
courses
name
semester_id
semesters
name
education_id
educations
name
On Mar 6, 11:35 am, Frederick C. [email protected]
And is there a semester with that id ?
Fred
This is so embarrising.
No, when doing rake up and down, all of my fixtures files are
interpeted differently.
so now I have to specify the id column, it’s not just a normal
incriment column, when migrating
Sorry for all the fuss, I just completely missed this.
On Mar 6, 3:28 pm, Frederick C. [email protected]
jep, you are 100% correct.
On Mar 6, 2:39 pm, gundestrup [email protected] wrote:
This is so embarrising.
No, when doing rake up and down, all of my fixtures files are
interpeted differently.
so now I have to specify the id column, it’s not just a normal
incriment column, when migrating
That is a rails 2.something differnce: if the id column is not
specified it is autogenerated according to some deterministic method.
THis is part of something called “foxy fixtures”. What it boils down
to is that you used to have to have stuff like
bobs_order:
user_id: 4
in orders.yml
and
bob:
id: 4
name: bob
in users.yml.
since this change you can have
bobs_order:
user: bob
and
bob:
name: bob
Because rails knows what id bob will be assigned it can wire things up
and you end up with neater fixture files without a million hardcoded
ids.
Fred
jep, I fixed the problem, by manually editing my .yml file…
I am so sorry for not realising the stupid simple issue.
It would be nice if there was a way to avoid editing every line on
your yaml file
Some kind of switch.
But I can’t find one.
Thanx for all of your patient help.
And have a wonderfull weekend.
regards
svend
On Mar 6, 9:44 pm, Frederick C. [email protected]