Hello, I have been trying to debug this issue and then i
realized that plugin was causing this.
I am using the example of search from railscasts but I have a
deep association model.
-----ERROR---------------------------------
NoMethodError in Browses#tracks
Showing app/views//tracks.html.erb where line #18 will_paginate ignores the :include with has_many raised:
You have a nil object when you didn't expect it! The error
occurred while evaluating nil.setTitle Extracted source (around
line #18 will_paginate ignores the :include with has_many):
15: 16: <% for track in @track do %> 17:
=> 18: <%=
track.trackTitle%> - <%= track.artist.name %> (<%=
track.dj_set.setTitle %>) 19:
20: <% end %> 21:
class Track belongs_to :dj_set belongs_to :artist end class
dj_set has_many :tracks, :dependent => :destroy end class artist
has_many :tracks end
------track.html.erb------ <% form_tag request.path, :method
=> 'get' do %> <% content_tag :label do %>
Search Tracks:
<%= text_field_tag :search, params[:search] %>
<% end %> <% end %>
<% for track in @track do %>
<h3 style="margin-bottom: 2px">
<%= track.trackTitle%> - <%= track.artist.name %> (<%= track.dj_set.setTitle %>)
</h3>
<% end %>
------ Track.rb model -------
def self.search(search, page)
paginate :per_page => 20, :page => page,
:include => [:artist, :dj_set],
:conditions => ['trackTitle like ?', "%#{search}%"], :order => 'created_at'
end
----- browse_controller.rb ------
def tracks
@track = Track.search(params[:search], params[:page])
end
This WORKS fine on page >2 and if any search is performed.
The eror is only shown on page one.
Correct output
Search Tracks: --intro--- Intro - A State of Trance (374) Intro
- A State of Trance (375) Intro - A State of Trance (373) Intro -
Trance Around the World (239) Intro - Trance Around the World
(238)
Thanks you! Cheers, Akshay