>
> Hi all,
>
> I'm using Rails 2.0,2 with Ruby 1.8.6 (Gems 0.8.4) and I'm having
> trouble in Chapter 3/4 with integration tests:
>
> ActionView::TemplateError (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) on line #7 of admin/book/
> _form.html.erb:
> 4: <%= text_field 'book', 'title' %></p>
> 5:
> 6: <p><label for="book_publisher">Publisher</label><br/>
> 7: <%= collection_select :book, :publisher_id, @publishers, :id, :name
> %></p>
@publishers is probably nil, that's what the error message seems to
indicate. How have you set it up in the controller?
//jarkko
--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi
>
> From publisher_controller:
>
> def list
> @publisher_pages, @publishers = paginate :publisher, :per_page =>
> 10
> end
>
> Paginate was installed using classic_pagination.
>
> From "_form.html.erb" :
> <p><label for="book_publisher">Publisher</label><br/>
> <%= collection_select :book, :publisher_id, @publishers, :id, :name
> %></p>
>
> <p><label for="book[author_ids][]">Authors</label><br/>
> <%= select_tag 'book[author_ids][]',
> options_from_collection_for_select(@authors, :id, :name,
> @book.authors.collect{|author| author.id}),
> { :multiple => true, :size => 5 }
> %>
> </p>
>
> I changed "@publishers" to "Publisher.find(:all)" and
> "@authors" to "(Author.find(:all)", after checking
> api.rubyonrails.org,
> which seems to work...
>
> I'm not sure why?
IIRC paginator is not part of the Rails core anymore in Rails 2, so
you might need to download some of the pagination plugins like
will_paginate. Not sure why it's not causing an error though, but
instead causing @publishers to be nil. You can check if the current
syntax is different from the one that was current when the book was
written.
You should generally never use calls like Publisher.find(:all) in the
views, btw. They're not part of the view logic and you should avoid
putting actual domain code in the views.
//jarkko
>
>
> On Aug 11, 11:16 pm, Jarkko Laine <jar...@jlaine.net> wrote:
>> On 12.8.2008, at 3.56, gumpster wrote:
>>
>>
>>
>>
>>
>>> Hi all,
>>
>>> I'm using Rails 2.0,2 with Ruby 1.8.6 (Gems 0.8.4) and I'm having
>>> trouble in Chapter 3/4 with integration tests:
>>
>>> ActionView::TemplateError (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) on line #7 of admin/
>>> book/
>>> _form.html.erb:
>>> 4: <%= text_field 'book', 'title' %></p>
>>> 5:
>>> 6: <p><label for="book_publisher">Publisher</label><br/>
>>> 7: <%= collection_select :book, :publisher_id,
>>> @publishers, :id, :name
>>> %></p>
>>
>> @publishers is probably nil, that's what the error message seems to
>> indicate. How have you set it up in the controller?
>>
>> //jarkko
>>
>> --
>> Jarkko Lainehttp://jlaine.nethttp://dotherightthing.comhttp://www.railsecommerce.comhttp
>> ://odesign.fi
> >
--