Rails pagination error - ruby-on-rails

I'm using the will_paginate plugin and I get the following error only when I'm running on a server rather than locally:
undefined method `total_pages' for []:Array
Extracted source (around line #8):
5: <% session[:page] = params[:page] %>
6: <h2>Previous Scenario</h2>
7: <% end %>
8: <%= will_paginate #scenarios, :next_label => 'Older', :prev_label => 'Newer' %>
9: <div class="box">
10: <% for scenario in #scenarios %>
11: <% #created = scenario.created_at %>
Any ideas?

Somehow, #scenarios is an ordinary Array for you and it can't be from Scenario.paginate() method because that one always returns a WillPaginate::Collection object.

Does your controller have the other half of the equation, e.g.
#scenario = Scenario.paginate(:page => params[:page]||1)
Alternatively I think you might have a plugin on the server side that is converting your Active Record set into a plain array. I'd need a bit more info to look at that.

Related

ActionView::Template::Error (undefined method `+' for nil:NilClass):

One of my pages keeps hitting this error:
ActionView::Template::Error (undefined method `+' for nil:NilClass):
15: <div class="look_list">
16: <% collection.each do |look| %>
17: <div class="look_book" id="<%= look.content_id %>">
18: <% thumbnail_image = (look.processing? ? "/assets/processing_placeholder.gif" : (look.image.url(:thumb) + "?#{look.updated_at.to_i}")) %>
19: <%= image_tag thumbnail_image || "/assets/processing_placeholder.gif",:class=> "look_image", :size => "118x118" %>
20: <script type="text/javascript">
21:
app/views/looks/index.html.erb:18:in `block in _app_views_looks_index_html_erb__3409922204803071014_68666020'
app/views/looks/index.html.erb:16:in `_app_views_looks_index_html_erb__3409922204803071014_68666020'
Some background, my site hit into 502 bad gateway 2 days ago. We managed to restart the site. However, it caused some connection issue with mongodb. This was resolved after we restart the DB. However, this one page keep hitting the error above. This has never happened before. Any one can help?
what is the value of look.image.url(:thumb) before line 18 executes? That is where the error is thrown, and it is the only place I am seeing a +
I'd check your data, to see if the crash caused data loss somewhere, in particular, on the data needed for that method
Try out something like this .....
<div class="look_list">
<% collection.each do |look| %>
<div class="look_book" id="<%= look.content_id %>">
<% thumbnail_image = look.image.url(:thumb) unless look.processing? %>
<% thumbnail_image.nil? ? "/assets/processing_placeholder.gif" : (look.image.url(:thumb) + "?#{look.updated_at.to_i}") %>
<%= image_tag thumbnail_image ,:class=> "look_image", :size => "118x118" %>
</div>
<% end %>
</div>

Pusher Chat Example Error

I am trying to work with tarnfeld's PusharChat-Rails
I downloaded the file, did the usual bundle install & db:migrate.
I changed the api key in PusherChat-Rails / app / views / layouts / application.html.erb
but I am getting this error
NoMethodError in Chat#view
Showing /Users/gkolan/work/PusherChat/app/views/chat/view.html.erb where line #22 raised:
undefined method `auto_link_urls' for #<#<Class:0x007fdddb772818>:0x007fdddb710230>
Extracted source (around line #22):
19: <ul id="messages">
20: <% #messages.each do |message| %>
21: <% user = ChatUser.find(message.user_id) %>
22: <li<% if user.id == #user.id %> class="you"<% end %>><strong><%= user.nickname %></strong> said:<br><%= auto_link_urls(message.message, { :target => "_blank" }) %></li>
23: <% end %>
24: </ul>
25: <div id="message-overlay"></div>
Rails.root: /Users/gkolan/work/PusherChat
I think its a very simple error. Could you please help me solve this?
Thanks in advance!
The auto_link_urls method has been deprecated for rails >= 3.1.0.
You may :
modify your Gemfile to use 3.0.9
add the rails_autolink gem to your Gemfile

Problem application Rails 2 using bundler

I am using Rails 2.3.11 end the error is:
NoMethodError in Configurations#index
Showing rails/ruby/1.8/gems/actionpack-2.3.11/lib/action_controller/templates/rescues/diagnostics.erb where line #7 raised:
private method `gsub' called for nil:NilClass
Extracted source (around line #7):
4: in <%=h request.parameters['controller'].humanize %>Controller<% if request.parameters['action'] %>#<%=h request.parameters['action'] %><% end %>
5: <% end %>
6: </h1>
7: <pre><%=h #exception.clean_message %></pre>
8:
9: <%= render :file => #rescues_path["rescues/_trace.erb"] %>
10:
My feeling is that #exception is null, since no exceptions were raised on page.
Try something like:
<% if !#exception.nil? %>
<%=h #exception.clean_message %>
<% end %>

need help with acts_as_ferret and will_paginate to play nice together

I have installed will_paginate and acts_as_ferret on my system for ruby rails.
My paginate seems to work fine before installing acts_as_ferret. When I put in the code to do searching I get the following error:
NoMethodError in Community#search
Showing app/views/community/_result_summary.rhtml where line #3 raised:
undefined method `total_entries' for []:Array
Extracted source (around line #3):
1: <% if #users %>
2: <p>
3: Found <%= pluralize(#users.total_entries, "match") %>.
4: </p>
5: <% end %>
If I take out the search function, paginate works but it's pointless because I can't do searches. Can any one help me out on this one??
Thanks!!
Stephen
undefined method `total_entries' for []:Array
eror itself shows that you are calling total_entries method which is not array method.
you get more than one user in your #users.
try
1: <% unless #users.blank? %>
2: <p>
3: Found <%= pluralize(#users[0].total_entries, "match") %>.
4: </p>
5: <% end %>
EDITED
TRY
1: <% unless #users.blank? %>
2: <p>
3: Found <%= pluralize(#users.length, "match") %>.
4: </p>
5: <% end %>

Ruby and Nil Object

I am developing a webapp (well trying to) in Ruby on Rails.
I have a partial render in my index.html.erb
<%= render :partial => "houses/index", :locals => #houses %>
index.html.erb is loaded when the user hits the root of my domain. This partial cause this error:
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 8
5: <th>Washrooms</th>
6: </tr>
7:
8: <% #houses.each do |house| %>
9: <tr>
10: <td><%=h house.short_desc %></td>
11: <td><%=h house.bedrooms %></td>
Trace of template inclusion: app/views/home/index.html.erb
All I would like to is display 5 houses on my Homepage (index.html.erb)
What am I missing to get this to work?
Many thanks
EDIT:
Houses_controller
NoMethodError in Home#index
Showing app/views/houses/_index.html.erb where line #10 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 #10):
7: Washrooms
8:
9:
10: <% #houses.each do |house| %>
11:
12: <%=h house.short_desc %>
13: <%=h house.bedrooms %>
Trace of template inclusion: app/views/home/index.html.erb
The value of :locals is supposed to be a Hash that defines local variables. So
<%= render :partial => "houses/index", :locals => {:houses => #houses} %>
and then
<% houses.each do |house| %>
To reiterate, since the new error you posted shows that you are still not doing it correctly:
If you're passing it through :locals, you want houses.each, not **#**houses.each. No snail. Local variables don't have a # prefix; instance variables do.
Locals takes a hash of local variables, like so:
<%= render :partial => "houses/index", :locals => { :houses => #houses } %>
Also, when you pass in a local variable to a partial, you should use it as a local variable rather than an instance variable within the partial, as so:
<% houses.each do |house| %>
# do stuff with each house
<% end %>
You don't need to pass it in :locals if it's an instance variable. Instance variables are available in all partials.
In your view:
<% #houses.each do |house| %>
# do stuff with each house
<% end %>

Resources