Gabriel,
this type of problems is the most common occurrence when building an
application; "*a variable is nil somewhere.*.". It is quite important that
you do something more than reading the trace.
The trace tells you that this happens when calling
"select_country_choices"...; this method is one liner in a helper module,
and it is accessing one variable (@countries).
So, the question you should be asking is: is @countries nil? let's put a
debug statement somewhere before the call that produces the exception.
And if you find that it is nil, the next step is: *who should set it?* the
call is from the students_helper, so it is likely that the code is in the
Students Controller... ah, the method to provide @countries is there, but *is
someone calling it*? (If not this is the problem; the guy who wrote the
tutorial forgot to mention that this method should be called.. let's
see: *where
should I put the call?* in all the actions that need it? uhm, I remember
this thing about "filters"...).
This is the process that you should follow next time (I know that you are
able to); not stop at the exception and say "it does not work". Anyone one
can do a "homework", following mechanically the example; but this is not
mechanical, and so it is a lot more useful.
-------
Having said that, in the tutorial I forgot to mention that you need a
before_filter in the students_controller:
before_filter :countries, :only => [ :new, :edit, :update, :create ]
By the way, the line is in the zip of the project (the link is in section
"2. An international Online College").
In any case, kudos for following line by line the construction of the
project (you are probably one of the few, if not the only one, who tried
that). But I invite you to do something more next time; if there is an
error, dive into it, and see if you can fix it... or at least go near to the
exact reason. The feeling will be special,
Raul
On Tue, Dec 9, 2008 at 7:24 AM, Gabriel <[EMAIL PROTECTED]> wrote:
> Hi folks.
> I'm following the Action View Helpers tutorial but something's going wrong.
>
> Everything goes well until step 2.5, where we populate the database with
> some sample data.
>
> When I run the application, I can view the "index" and "show" views, but
> the "edit" and "new" views (where the 'editable_student_form' partial is
> rendered), I'm getting a "NoMethodError" when calling
> "select_country_choices" (at least is where the trace stops).
>
> The error message is:
>
> You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.map"
>
> I'm not getting the "select_country_choices" when I call "Student.methods"
> or "StudentsHelper.methods" in Rails Console as well.
>
> How can I get things right?
>
> Thanks,
> Gabriel.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---