On 24 November 2010 19:05, Andrew Davis <lists@ruby-forum.com> wrote:
> Bill, that doesn't seem to be working. It seemed to be at first until I
> tried to do more with the application.
>
> My shared/_task_orders.html.erb
> <ul type="none">
> <% @all_task_orders.each do |task_order| %>
> <% unless task_order.year != @last_task_order.year %>
Not related to your problem, but if this is the only place you are
referencing the task_orders, and you have the test here so that you
only show some of them, you would be better to only pick up the
relevant ones in the controllers and pass that array to the view.
Then you do not need the test in the view.
> <li>     <%=h link_to "#{task_order.name}",
> task_order_criteria_path(task_order) %> - <%=h task_order.year %> Q<%=h
> task_order.quarter %></li>
> <% end %>
> <% end %>
> </ul>
> <br />
>
> My task_orders_controller
> class TaskOrdersController < ApplicationController
> ...
> def index
> @task_orders = TaskOrder.search(params[:search], params[:page])
> @last_task_order = TaskOrder.find(:first)
> @all_task_orders = TaskOrder.all
> end
> ...
> end
>
> I'm getting:
> NoMethodError in Criteria#index
Why does that say Criteria#index when you have shown us
TasksOrderController#index?
>
> Showing app/views/shared/_task_orders.html.erb where line #2 raised:
>
> 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.each
>
> Extracted source (around line #2):
>
> 1: <ul type="none">
> 2: <% @all_task_orders.each do |task_order| %>
The error message is saying that @all_tasks_orders is nil. I see that
this is in a partial, have you passed the data across to the partial.
The mechanism for doing this varies with Rails version. The Rails
Guide on Layouts and Rendering discusses the various methods for
getting data to partials. The other possibility is of course that
@all_task_orders was nil in the first place, possibly because the
partial has been called from Criteria#index and that route has not set
@all_task_orders.
Are you aware of how to use ruby-debug to break into your code (View,
Controller or Model) in order to check code flow and inspect data to
see what is happening? Have a look at the Rails Guide on debugging to
see how. This is invaluable and I strongly suggest you have a look a
this. It will save a lot of time waiting for response from the list
if you can just break into the code and work out for yourself why
something is not working.
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment